Gunicorn doesn't log real ip from nginx
The problem is that you need to configure gunicorn
's logging, because it will (by default) not display any custom headers.
From the documentation, we find out that the default access log format is controlled by access_log_format
and is set to the following:
"%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
where:
h
is the remote addressl
is-
(not used)u
is-
(not used, reserved)t
is the time stampr
is the status lines
is the status of the requestb
is length of responsef
is referrera
is user agent
You can also customize it with the following extra variables that are not used by default:
T
- request time (in seconds)D
- request time (in microseconds)p
- the process id{Header}i
- request header (custom){Response}o
- response header (custom)
To gunicorn
, all requests are coming from nginx so it will display that as the remote IP. To get it to log any custom headers (what you are sending from nginx
) you'll need to adjust this parameter and add the appropriate variables, in your case you would set it to the following:
%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" "%({X-Real-IP}i)s"