« Reverse proxy (X-Forwarded-For) patches for WordPress comments and Bad Behaviour | Home | Converting between int and std::string in C++ »
Correcting IP address of PHP behind a reverse proxy
By admin | November 14, 2010
As described in our previous post, normally the PHP REMOTE_HOST variable only appears as the address of the trusted proxy server. As was also described in the past, this messes up all of the PHP scripts not explicitly designed to work with REMOTE_HOST. But now we have a solution for this – the apache mod_rpaf. This mod is capable of changing the IP variables in the server superglobal to the actual IP.
Prerequisites
Install the libapache2-mod-rpaf:
sudo apt-get install libapache2-mod-rpaf
Procedure
- Open /etc/apache2/httpd.conf and add the following text, replacing 1.2.3.4 with the name of your trusted proxy server:
<IfModule mod_rpaf.c> RPAFenable On RPAFsethostname On RPAFproxy_ips 1.2.3.4 </IfModule>
- Save the file and restart the Apache server:
sudo /etc/init.d/apache2 restart
Note: If you are getting 502 Bad Gateway errors coming out of your gateway and you are using IIS, disable the TCP port forwarding in IIS Admin. It can be found in the ARR page -> Proxy. Then uncheck “include client TCP numbers”.
If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
Topics: Internet, Linux | 5 Comments »
January 13th, 2025 at 06:00
… [Trackback]
[…] Find More on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]
January 19th, 2025 at 16:29
… [Trackback]
[…] Here you can find 61938 additional Info on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]
January 19th, 2025 at 20:08
… [Trackback]
[…] There you will find 78506 more Info to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]
January 20th, 2025 at 05:34
… [Trackback]
[…] Read More on on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]
January 28th, 2025 at 06:34
… [Trackback]
[…] Find More to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]