When the request arrives to Apache, the client IP address is
127.0.0.1. We need to configure Apache to accept the IP address from X-Real-IP or X-Forwarded-For headers set by Nginx.To solve this problem I use
mod_rpaf that does exactly the opposite of mod_proxy_add_forward.
In my Nginx virtualhost configuration I have something like:
server {
...
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
...
}
...
}
This also applies if your are using a different webserver as front-end such as Lighttpd or another instance of Apache.