解決了需要在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"
雷雷
因為你沒配置