Nginx + apache (for PHP) with real IP addresses in logs
I was trying to get nginx to work with apache 2.2.15. The idea is that nginx will ofer the static content and apache the PHP content.
Very easy to do and a lot of documentation is available over the internet on how to do it. However, i encountered some issue when i was trying to get nginx to send the real IP address of the visitor to the apache server and not the localhost ip (127.0.0.1).
The solution came with the mod_rpaf module for apache. You can download it from
here. In case that website will go down for some reasons, i've attached to this post the latest available version of this module (released 01-Jan-2008 22:42 - that's more than 2 years ago).
Here is how my configuration looks like:
1. Apache2 conf (related with mod_rpaf, the rest you can google for help)
Code:
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 10.255.254.1
RPAFheader X-Forwarded-For
Note: I have both 127.0.0.1 and 10.255.254.1 ips configured as local IP. Most probably you will have only 127.0.0.1...
2. nginx conf (related with proxy redirection to apache2)
Code:
in the server section
location ~ \.php$ {
proxy_pass http://127.0.0.1:82;
}
in the http section
proxy_redirect off;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_ignore_client_abort off;
proxy_intercept_errors on;
proxy_ignore_headers Expires Cache-Control;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;