We are running a Rails application on Unicorn + Nginx. The server has two NICs that we use. eth0
handles requests for the public internet, and eth2
handles requests from our private network.
When a request comes through eth0
, the nginx logs show the public IP, and the Rails logs also show this IP. However, when a request comes through eth2
, the nginx logs show the private IP correctly (e.g. 192.168.5.134
), but the Rails logs show 127.0.0.1
.
So it seems like public requests on eth0
get their X-Forwarded-For
header set correctly, but this isn't happening for requests on eth2
.
Our nginx config is pretty basic:
upstream example.com {
server unix://var/www/example.com/shared/sockets/unicorn.socket fail_timeout=0;
}
...
server {
listen 443 ssl;
...
location @example.com {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real_IP $remote_Addr;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if ($host ~* "^(.+)\.example.com$") {
set $subdomain $1;
}
proxy_pass http://example.com;
}
Any ideas?