Get The Real IP from WebServer That Run Behind Reverse Proxy

As my previous post about Reverse Proxy, the technique that you can use to reduce server load and at the same time you will have more faster HTTP Response from user experience.

One of the issue with Reverse proxy, that all the webserver that run behind the proxy only accept HTTP Request from proxy. So, if the webserver receive HTTP Request from the proxy, that means webserver only acknowledge IP’s from Proxy only. You can check this by open access_log of the webserver, and you will notice that all HTTP Request came from one IP, that is your Proxy’s IP.

Why we should care about this? because your web statistic (hits, pageview, visitor, etc) will be ruin. your data wouldn’t be quite informative to analyze.

In order to fix this, you have to configure on both side, your Reverse Proxy and your web server.

For this article i’m using Nginx as Reverse Proxy and Apache/Httpd as web server.

Nginx

At first, your Nginx should have HttpProxyModule installed. And then, add the parameter to your nginx configuration file.

example:

location / {
       proxy_pass http://myserver;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Apache / Httpd

Your Apache you also need to install necessary module, which is rpaf_module.  after that you must put this line to your apache / httpd configuration file.

*You can also put this configuration on separated file and put it under httpd conf.d/ directory. (/etc/httpd/conf.d/rpaf.conf)

example

LoadModule rpaf_module modules/mod_rpaf-2.0.so

RPAFenable On
 RPAFsethostname On
 RPAFproxy_ips 127.0.0.1 #or assign this with your Reverse Proxy local IP.

Then reload your Nginx and Apache service to apply the changes.

Take a look at your apache access_log and now you get your HTTP Request real IP’s.

boi

source: kompasiana

Boyke D Triwahyudhi is a server guy that love to design a system not only by technology, but he focused on architecture approach as well. Grew up as Delphi programmer and currently enjoying playing on web and mobile ecosystem.

Comments

comments