[Solved] Why doesn't nginx upstream forward the browser's IP address?
阿神
阿神 2017-05-16 17:13:22
0
2
803

Solved the need to add these sentences under 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;

Why does nginx upstream not forward the browser's IP address, but forwards the address of the nginx server?

My forwarding nginx configuration is as follows:

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

The actual server configuration forwarded to is as follows:

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

        include php_fcgi.conf;
        include pathinfo.conf;
    }

But the problem is that every time I visit the website, the value of $_SERVER['REMOTE_ADDR'] in php is the forwarding nginx server address 10.24.240.132 (the forwarding server listens to port 80, the address is 10.24.240.132, both php servers are It is listening to port 8080, and the forwarding server is also used as one of the php servers), not the browser address:

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

闭关修行中......

reply all(2)
Ty80
location / {
        proxy_pass   http://http://mysite.com;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
}
为情所困

Because you didn’t configure it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template