Sep
24

使用Nginx代理模式,后端程序得到用户IP的方法

在nginx中设置:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
后端程序可以从Server变量HTTP_X_REAL_IP和HTTP_X_FORWARDED_FOR中获取用户的ip地址。
HTTP_X_REAL_IP的值是nginx得到的用户REMOTE_ADDR

共计 0 条评论

NAME:

required

E-MAIL:

required, will not be published

HOMEPAGE:

CONTENT: