Nginx配置让后端缓存服务器能记录客户端实际IP?

rgone 发布于 2012/06/26 16:25
阅读 1K+
收藏 3

按照网上的教程来配置Nginx的Sever段,但是后端varnish或Squid仍然获取不到客户端真实IP,求解:

Nginx Server配置:

server
  {

    listen       80;
    server_name  www.daily.com;
    index index.html index.htm;
    root	/usr/local/Programs/;
	location /
    {	
		proxy_set_header      Host $host;
		proxy_set_header      X-Real-IP $remote_addr;
		proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://squidserver;

    }
    log_format  daily_logs  "$remote_addr^A$remote_user^A$time_local^A$request_method^A$uri^A$args^A$server_protocol"
        "^A$status^A$body_bytes_sent^A$http_referer"
        "^A$http_user_agent";
    access_log  /home/data/nginx/nginx_logs/www.daily.com/daily_logs.log  daily_logs;
  }

Squid日志:

10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/ HTTP/1.0" 200 36306 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT
10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/template/shop/css/base.css HTTP/1.0" 304 238 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT
10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/template/common/js/jquery.js HTTP/1.0" 304 239 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT
10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/template/shop/css/shop.css HTTP/1.0" 304 239 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT
10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/upload/logo.gif HTTP/1.0" 304 238 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT
10.16.6.101 - - [26/Jun/2012:15:47:08 +0800] "GET http://www.daily.com:9091/upload/banner1.jpg HTTP/1.0" 304 240 TCP_REFRESH_UNMODIFIED:FIRST_UP_PARENT

我的客户端实际IP是10.16.6.28!

加载中
0
鉴客
鉴客

这个没办法的,Nginx 是可通过 set_real_ip_from 指令来配置允许 Proxy 端的 IP 设置,但是 varnish 和 squid 不知道可不可以

鉴客
鉴客
回复 @饶过 : 是的
rgone
rgone
您的意思set_real_ip_from可以让Nginx获取前端代理发送的正式IP?
返回顶部
顶部