Varnish (reverse proxy) + nginx with php and REMOTE_ADDR issue

Hi there.

I have Varnish as reverse proxy to nginx what serve php. Varnish sends
to nginx REMOTE_ADDR as 127.0.0.1.

My php config:

location ~ .php$ {
try_files $uri @404;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_pass unix:/var/run/spawn-fcgi/php5.sock-1;
fastcgi_index index.php;
}

location @404 { return 404; break; }

I think I should change fastcgi_param REMOTE_ADDR to insert
X-forward-for here but I don’t know if this is even possible. I
googling around and I didnt find anything about how change REMOTE_ADDR
what Varnish sending for nginx so I think to make workaround and
change in nginx REMOTE_ADDR to X-FORWARD-FOR.

Hi,

On Jan 3, 2010, at 2:24 PM, Piotr K. wrote:

I think I should change fastcgi_param REMOTE_ADDR to insert
X-forward-for here but I don’t know if this is even possible. I
googling around and I didnt find anything about how change REMOTE_ADDR
what Varnish sending for nginx so I think to make workaround and
change in nginx REMOTE_ADDR to X-FORWARD-FOR.

http://wiki.nginx.org/NginxHttpRealIpModule

V/r,
Rob

I saw that but I don’t understand how can I use it in fastcgi_parms.

fastcgi_param REMOTE_ADDR $real_ip_header;

This can work?

No use
http://wiki.nginx.org/NginxHttpRealIpModule#real_ip_header
put this into either the in the http, server or you location section.

set_real_ip_from 127.0.0.1; (or what ever your varnish ip address is)
real_ip_header X-Forwarded-For;

and just leave it as fastcgi_param REMOTE_ADDR $remote_addr;

V/r,
Rob

Thank you very very much!