nginx + varnish + nginx 获取客户端地址

nginx 

http {

...

set_real_ip_from 153.37.232.0/24;

real_ip_header X-Forwarded-For;

...

}

 

varnish

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;
  }
}

...

}

 

 

nginx

http {

...

set_real_ip_from 10.0.0.0/8;

real_ip_header X-Real-IP;

...

}

 

posted @ 2016-04-12 18:22  zenghui940  阅读(238)  评论(0编辑  收藏  举报