Compdigitec Labs

« | Home | »

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

  1. 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>
    
  2. 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 | 8 Comments »

8 Responses to “Correcting IP address of PHP behind a reverse proxy”

  1. payday loans quebec Says:
    August 2nd, 2026 at 10:20

    … [Trackback]

    […] Read More on to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  2. คลินิกเปิดดึก Says:
    August 9th, 2026 at 19:08

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  3. ศูนย์ดูแลผู้สูงอายุ Says:
    August 21st, 2026 at 20:43

    … [Trackback]

    […] There you can find 81784 additional Information to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  4. เครื่องสแกนบาร์โค้ด Says:
    September 5th, 2026 at 20:43

    … [Trackback]

    […] Read More Info here on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  5. 如何登录WhatsApp网页版 Says:
    September 6th, 2026 at 20:28

    … [Trackback]

    […] Read More Information here to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  6. Van Says:
    September 8th, 2026 at 00:57

    I got this site from my buddy who shared with me concerning this website and now this time I am browsing
    this web page and reading very informative posts
    at this place.

    My blog … Van

  7. xüm tablets | plur beyond molly | buy xum plur | plur tablets | plur gummies | beyond molly | xum beyond shrooms | plur xum | xum community pack | xum wholesale | xum plur for sale | Says:
    September 8th, 2026 at 01:57

    … [Trackback]

    […] Here you can find 69630 more Information on that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  8. Pegasus เว็บหวยออนไลน์เว็บตรง Says:
    September 8th, 2026 at 21:19

    … [Trackback]

    […] Find More Info here to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

Comments