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 a nginx reverse-proxy (server A) running in front of another nginx server (B).

However, A doesn't seem to pass the IPs correctly to server B.

Even though I have

    proxy_set_header   X-Real-IP  $remote_addr;
    proxy_set_header   Host $host;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

these lines in my config.

I know for Apache you simply load the RPAF-module.

Is there something similar for nginx ?

Cheers

share|improve this question

2 Answers 2

up vote 0 down vote accepted

There is a nice overview of modules here: http://wiki.nginx.org/Modules Specifically you need this: http://wiki.nginx.org/HttpRealIpModule

share|improve this answer
    
Cheers, this fixed the issue for both logs and PHP. –  Tuinslak Mar 24 '11 at 9:26

Some more detail would be helpful on what you mean by "doesn't pass the IPs" - where you're seeing the wrong IP, and what you're expecting.

I'm going to go out on a limb and say that you're probably seeing the reverse proxy's address instead of the client's address in the logs - you can alter your log format to show the contents of the X-Forwarded-For header (the example below is a tweak to the default combined format):

log_format proxied_combined '$http_x_forwarded_for - $remote_user [$time_local]  '
                            '"$request" $status $body_bytes_sent '
                            '"$http_referer" "$http_user_agent"';
access_log logdir/access.log proxied_combined;
share|improve this answer
    
Yes, indeed, both logs as PHP ($_SERVER['REMOTE_ADDR'] for example) give the proxy's address. –  Tuinslak Mar 24 '11 at 7:50

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.