Nginx与Varnish下获取访客的真实IP地址

首先,nginx -V 查看是否有启动 “–with-http_realip_module” 模块,必须启用才行。

sudo vi /etc/varnish/default.vcl

sub vcl_recv 模块加入:


if (req.restarts == 0) {
                if (req.http.x-forwarded-for) {
                set req.http.X-Forwarded-For =
                        req.http.X-Forwarded-For + ", " + client.ip;
                } else {
                set req.http.X-Forwarded-For = client.ip;
                }
        }
sudo vi /etc/nginx/nginx.conf

http {}模块内加入:

set_real_ip_from   127.0.0.1;
real_ip_header      X-Forwarded-For;

发表评论或回复

*选项为必填项,您的电子邮件地址不会被公开。

*
*