Nginx Logging – Log Both Client Remote Address and Proxies Address

loggingnginxreverse-proxy

I have an nginx instance set up behind multiple load balancing proxies, and I am using real_ip to get the clients IP address in remote_addr for processing by my Python application.

However in my logs I would like to log the proxy server that actually made the request, but $remote_addr has now been overwritten, and I can't find anything that says a copy of it is made.

How would I be able to accomplish this?

Best Answer

Your setup may have changed since you posted this question, but I had the same problem and there is finally a solution available. I'll post it here in case Google brings someone else to this page.

As @Michael Hampton♦ indicates in his answer to my own version of this question, nginx has added the variable $realip_remote_addr to the Real_IP module. It holds the original value of $remote_addr, allowing you to use/log both the originating client's IP and the IP of the server that sent the actual request to nginx. This was added to version 1.9.7, as of November 2015.

Related Topic