Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
You can only do this if you do not use the real ip module. Then your Python app has to implement the functionality. –  Michael Hampton Mar 10 '13 at 4:13

2 Answers 2

Dont really get if you want to log at nginx side or inside your application>

For nginx side you can use $http_x_forwarded_for in nginx log_format definition, something like this:

log_format  main  '$remote_addr - $remote_user [$time_local] [$msec] [$request_time] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
share|improve this answer
    
This doesn't work if you use the real ip module, at that point $remote_addr contains the same thing as X-Forwarded-For. I want to log the proxy servers address, and send the real IP on to the remote server as REMOTE_ADDR on uwsgi. –  X-Istence Mar 12 '13 at 6:26

The module itself seams to not support that. However, reverse proxies (for which real_ip is mostly used) may provide a HTTP header field containing the proxies IP address.

Unfortunately, you cannot check whether the address has been rewritten or not, so a client not connecting through a real_ip-enabled proxy could forge the header field.

Check your proxy's doc, maybe you can use a HTTP header field for the IP address.

share|improve this answer
    
No such luck unfortunately. The proxy in this case doesn't have a setting to have it forward the incoming address as a header :/ –  X-Istence Mar 12 '13 at 6:27
    
Then you might want to emulate real_ip's behaviour by setting the variables yourself. Maybe a nicely placed if with a simple set will do the trick. –  Lukas Mar 12 '13 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.