Welcome! Log In Create A New Profile

Advanced

IP Address fastcgi param

Posted by domino 
IP Address fastcgi param
April 08, 2012 12:20PM
I've configured nginx with the real ip module. Most production traffic is forwarded through a 3rd party proxy to 1st party software LB (nginx for 443 traffic and HA proxy for 80 traffic), then now on to nginx for the web application (php-fpm). I'm not able to get an accurate REMOTE_ADDR or other server variable for the end-user's IP address for users who connect through the proxy setup and users who connect direct to the server (via hostnames) at the same time.

If I add this line to the fastcgi.conf:
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;

I am able to get the remote_addr for the users who connect through the proxies. However, if I connect to the server avoiding the proxies (using my hosts file), then the REMOTE_ADDR (and other similar variables) are empty.

Is there any configuration that would handle both conditions? Is there a way to write conditional logic into the fastcgi conf file?
Re: IP Address fastcgi param
April 08, 2012 12:30PM
I should mention, if I comment out
## fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
in the config, then the REMOTE_ADDR shows correctly when connecting directly to the server (via hosts file), and does not show correctly for the proxy traffic. I put it back in, and it shows correctly for the proxy traffic but not for direct (via hosts file) traffic.

And if I set my hosts file to connect to the intermediary LB (nginx proxy), it displays the correct REMOTE_ADDR.



Edited 1 time(s). Last edit at 04/08/2012 12:34PM by domino.
Re: IP Address fastcgi param
April 09, 2012 12:34PM
I solved this issue. There was an error in the nginx.conf file with the set_real_ip_from and the order of configuration.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 190
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready