I am using a loadbalancer in my current setup, requests come from ip 10.71.128.13
.
I am using Nginx as a front to a Gunicorn backend. I want to get the real IP address of the visitor and log it (not the loadbalancer IP).
My nginx.conf:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # GET REAL IP set_real_ip_from 10.71.128.12; set_real_ip_from 10.71.128.13; set_real_ip_from 10.71.128.14; real_ip_header X-Forwarded-For;
My server block 'example.conf'
# HTTPS server { etc.... location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; proxy_buffering on; } }
An example log entry:
10.71.128.13 - - [10/Jun/2014:13:27:58 +0100] "POST /example/ HTTP/1.1" 200 25 "https://example.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
Sadly this configuration just returns the loadbalance IP and not the visitor's IP address... Can anyone help?