Archive

Posts Tagged ‘nginx real ip address’

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

September 14th, 2010 2 comments

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.