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?