[已解决]nginx upstream为什么没有把浏览器的ip转发过去?
阿神
阿神 2017-05-16 17:13:22
0
2
781

解决了需要在server下加这几句

            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;

nginx upstream为什么没有把浏览器的ip转发过去,而是转发的转发nginx服务器的地址?

我的转发nginx配置如下:

upstream mysite.com{
      server 10.24.240.132:8080;
      server 10.24.155.103:8080;
      ip_hash;
}

server
{
    listen       443;
    server_name  mysite.com;

    ssl on;
    ssl_certificate /etc/ssl/crt/server.cer;
    ssl_certificate_key /etc/ssl/crt/server.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;

    ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";

    ssl_prefer_server_ciphers on;

    location / {
            proxy_pass http://mysite.com;
        }
}

实际转发到的服务器配置如下:

    location ~ .*\.php.*
    {
        fastcgi_param HTTPS on;

        include php_fcgi.conf;
        include pathinfo.conf;
    }

但问题是我每次访问网站,php的$_SERVER['REMOTE_ADDR']的值都是转发nginx服务器地址10.24.240.132(转发服务器监听80端口,地址是10.24.240.132,两个php服务器都是监听8080端口,转发服务器也作为其中一个php服务器),而不是浏览器地址:

 "REMOTE_ADDR" => "10.24.240.132"
  "REMOTE_PORT" => "6324"
  "SERVER_ADDR" => "10.24.240.132"
  "SERVER_PORT" => "8080"
  "SERVER_NAME" => "10.24.240.132"
阿神
阿神

闭关修行中......

全部回复(2)
Ty80

雷雷

为情所困

因为你没配置

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板