使用nginx反向代理后,无法获取用户真实IP

    server {
        listen       80;
        server_name  www.ttdong.com;
        charset utf-8;
        location ~* \.(ico|gif|jpg|jpeg|png|bmp|swf|js|css)$ {    #指定缓存文件类型
            expires 365d;    
            access_log off;                                                    #设置浏览器过期时间
            root /datacached/sd;                                            #静态文件根目录目录(必须对应proxy_temp_path)
            proxy_store on;                                                    #开启缓存机制
            proxy_store_access user:rw group:rw all:rw;                        #缓存读写规则
            proxy_temp_path /datacached/sd;                                    #存放静态文件的缓存目录
            #proxy_set_header Host $host; 
            proxy_set_header X-Forwarded-For $remote_addr;        
            proxy_set_header  X-Real-IP  $remote_addr;
            if ( !-e $request_filename) {                                    #正则表达式,匹配缓存目录中的文件与源文件是否存在)        
                proxy_pass  http://SportsDay;                            # IIS 应用的服务器地址
            }
        }
        location ~* \.(html|htm)$ {
            expires    5h;
            access_log off;
            proxy_pass http://SportsDay;
        }
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_pass http://SportsDay;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        } 
    }

 上面就是我在nginx.conf文件中配置。

posted @ 2013-05-22 22:01  小气鬼  阅读(490)  评论(0)    收藏  举报