现大部分站长的网络安全意识增强,许多网站部署了WAF进行攻击防御,对于有支付功能的网站需要对支付回调设置允许规则,否则会出现用户支付后不到账的情况,以下是支付宝回调请求的特征:
请求方法:POST
User-Agent:Mozilla/4.0
根据特征在Nginx进行代码配置:
location = /payment/notify {
# 只允许POST方法
if ($request_method != POST) {
return 405; # Method Not Allowed
}
# 只允许User-Agent完全为Mozilla/4.0
if ($http_user_agent != "Mozilla/4.0") {
return 403; # Forbidden
}
}