$ apachectl -v Server version: Apache/2.4.7 (Ubuntu)
Server IP
Web Client IP
192.168.33.10
192.168.33.11
Web Client -> Nginx -> Apache -> PHP Website
When i use nginx to proxy to apache, apache gets the ip address of nginx proxy as the client. Through the apache log files, the PHP website running on the apache backend will all receive the same IP address ( 127.0.0.1, if apache and nginx are running in the same server).
Apache website configuration
My Apache listens 8013 port and accesses directory /www
Very useful, but… When i want to collect client IPs, it got all “127.0.0.1” in PHP script
Luckily, nginx provides a HTTP X-Forward-For header containing the client real ip address to allow Apache to recognize the origin client IP.
Install Apache rpaf module
1
$ sudo apt-get install -y libapache2-mod-rpaf
Check Apache rpaf module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ cat /etc/apache2/mods-available/rpaf.conf <IfModule rpaf_module> RPAFenable On
# When enabled, take the incoming X-Host header and # update the virtualhost settings accordingly: RPAFsethostname On
# Define which IP's are your frontend proxies that sends # the correct X-Forwarded-For headers: RPAFproxy_ips 127.0.0.1 ::1
# Change the header name to parse from the default # X-Forwarded-For to something of your choice: # RPAFheader X-Real-IP </IfModule>
Enable Apache rpaf module
1
$ sudo a2enmod rpaf
Add apache website rpaf module support
1 2 3 4
RPAFenable On RPAFsethostname On RPAFproxy_ips 127.0.0.1 xx.xx.xx.xx RPAFheader X-Real-IP
xx.xx.xx.xx is your proxy server ip address(es), multiple addresses can be space separated. It will tell mod_rpaf which host to get X-real-IP headers from.