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 | 9 Comments »

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

  1. marbo 9000 Says:
    November 14th, 2024 at 01:21

    … [Trackback]

    […] There you will find 22640 more Info to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

  2. Nextspin Says:
    November 15th, 2024 at 21:41

    … [Trackback]

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

  3. เว็บสล็อตมาแรง ทุกค่ายเด็ด Says:
    November 18th, 2024 at 03:35

    … [Trackback]

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

  4. try this out Says:
    December 1st, 2024 at 15:08

    … [Trackback]

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

  5. เรียนสัก Says:
    December 1st, 2024 at 21:23

    … [Trackback]

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

  6. pgslot168 Says:
    December 4th, 2024 at 04:20

    … [Trackback]

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

  7. pgslot Says:
    December 8th, 2024 at 21:09

    … [Trackback]

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

  8. เครื่องซีลสูญญากาศ Says:
    December 19th, 2024 at 06:27

    … [Trackback]

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

  9. watch now Says:
    December 28th, 2024 at 05:37

    … [Trackback]

    […] There you will find 47923 more Info to that Topic: compdigitec.com/labs/2010/11/14/correcting-ip-address-of-php-behind-reverse-proxy/ […]

Comments