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.

Install the libapache2-mod-rpaf:

sudo apt-get install libapache2-mod-rpaf


  1. Open /etc/apache2/httpd.conf and add the following text, replacing with the name of your trusted proxy server:
    <IfModule mod_rpaf.c>
    	RPAFenable On
    	RPAFsethostname On
  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: HTTP (Internet), Linux | 5 Comments »

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

  1. Aer conditionat Says:
    August 24th, 2021 at 17:12

    … [Trackback]

    […] Read More Information here on that Topic: […]

  2. relx Says:
    October 1st, 2021 at 19:33

    … [Trackback]

    […] Information on that Topic: […]

  3. Firearms For Sale Near Me Says:
    October 25th, 2021 at 18:55

    … [Trackback]

    […] Find More to that Topic: […]

  4. Dark0de Market Says:
    October 30th, 2021 at 11:02

    … [Trackback]

    […] Find More on on that Topic: […]

  5. situs dewaqq Says:
    November 8th, 2021 at 13:10

    … [Trackback]

    […] Find More Information here to that Topic: […]