Welcome! Log In Create A New Profile

Advanced

Nginx reverse proxy - not showing real IP

Posted by eXDee 
Nginx reverse proxy - not showing real IP
November 10, 2011 09:29PM
Hey there,
Just moved servers, transplanting configs almost exactly for a nginx server acting as a reverse proxy in front of apache, which listens on localhost.
nginx: nginx version: nginx/1.0.9
Server version: Apache/2.2.20 (Ubuntu)

However, its not seeing the real IP in apache:
site.com:80 127.0.0.1 - - [10/Nov/2011:09:53:22 +1100] "GET /file.php HTTP/1.0" 200 2630 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

This was solved with adding x-forwarded-for when i first set this up, but its no longer working for some reason on this new server

the output of phpinfo however shows this info, with my IP replaced with 1.2.3.4
#########
Apache Environment
Variable Value
HTTP_HOST site.com
HTTP_X_REAL_IP 1.2.3.4
HTTP_X_FORWARDED_FOR 1.2.3.4
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 127.0.0.1

HTTP Headers Information
HTTP Request Headers
HTTP Request GET /info.php HTTP/1.0
Host site.com
X-Real-IP 1.2.3.4
X-Forwarded-For 1.2.3.4
#######


/etc/nginx/conf.d/proxy.conf:
#######
#Cache Params
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=cachezone:64m max_size=2048m inactive=512m;
proxy_temp_path /var/lib/nginx/proxy;

map $http_accept_encoding $gzip {
default "";
~gzip " gzip";
}

proxy_cache_key "$scheme://$host$request_uri$gzip";
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_redirect off;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header Set-Cookie;
client_max_body_size 10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;

open_file_cache max=1000 inactive=120s;
open_file_cache_min_uses 1;
open_file_cache_valid 240s;
open_file_cache_errors on;

upstream backend {
server 127.0.0.1;
}
#######

/etc/nginx/proxy_params appears to be a new file, but i cant see it included anywhere so i assume its not being used. Tried removing it and it didnt help.
#######
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#######

Why is this suddenly not working on the new server with the same config?
Re: Nginx reverse proxy - not showing real IP
November 12, 2011 03:44AM
Right, the problem was caused during an apache2 upgrade where mod_rpaf couldn't be/wasn't loaded. Installing this fixes the issue if anyone misses this like I did.
Re: Nginx reverse proxy - not showing real IP
December 22, 2011 06:15AM
Still Apache ErrorLog showing 127.0.0.1 for me, and quite desperate at the moment as I'm suffering a DoS trial and completely unable to catch attacker IP as Apache2 ErrorLog (with mod_qos) only showing 127.0.0.1.

My config is right the same that u show here except for the Apache environment, I think i do not have such variables. However, I have rpaf and next lines in Apache conf and my virtual hosts which show me the real client IP only in CustomLog, not in ErrorLog ::

[apache2.conf]
SetEnvIf X-Forwarded-For "^([0-9.]+)" forwarded
SetEnvIf Request_URI "^/myconnchecker.php" dontlog
#
LogFormat "%{X-Forwarded-For}i %D %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" trueip

[vhost conf]
CustomLog /var/log/apache2/mydomain.com-access.log trueip env=!dontlog


Quite desperate at the moment .....seeing lot of "access denied, QS_SrvMaxConnPerIP rule: max=50, concurrent connections=51, c=127.0.0.1" and unable to catch the attacker.
Re: Nginx reverse proxy - not showing real IP
December 28, 2011 01:06PM
no one knows?
:(
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 166
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready