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

Piotr Karbowski jabberuser at gmail.com
Sun Jan 3 23:24:23 MSK 2010


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.



More information about the nginx mailing list