Home > IT Architecture > How to get the real user ip address when using nginx as reverse proxy(from backend apache server)

How to get the real user ip address when using nginx as reverse proxy(from backend apache server)

September 14th, 2010

To put an elephant into a fridge-three steps(which I think you already knew it):

Firstly(open the fridge):In nginx,add a line in /usr/local/nginx/conf/proxy.conf:
proxy_set_header        X-Real-IP       $remote_addr;
#Note:Add this just in proxy.conf,repetitive addition in nginx.conf location and server place will result your backend server log repetitive times.

Secondly(put the elephant in):In backend apache server,add the following lines in place VirtualHost or Server:
LogFormat "%{User-agent}i %{X-Real-IP}i"
TransferLog /var/log/test.log
Thirdly(close the fridge):reboot nginx and backend to take your changes effect.
killall nginx && /usr/local/nginx/sbin/nginx

Y/etc/init.d/apache2 restart #or /etc/init.d/httpd restart
All right.Now,use tail -f /var/log/apache2/yoursite-access.log to see the real user ip address not filtered by your reverse nginx server.

Good Luck!


  1. club penguin money maker
    November 20th, 2010 at 19:15 | #1

    I added your site to my RSS reader :D

    • lamp-linux
      November 21st, 2010 at 12:40 | #2

      Thanks for your concerning

Comments are closed.