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

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

  1. รีวิวเกมสล็อต ค่าย PG SLOT Says:
    March 28th, 2025 at 00:15

    … [Trackback]

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

  2. โรงงานผลิตสปริง Says:
    April 2nd, 2025 at 07:25

    … [Trackback]

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

  3. แนะนำ เกมยิงปลา lsm99 เดิมพันง่าย Says:
    April 5th, 2025 at 20:54

    … [Trackback]

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

  4. chadabet Says:
    April 17th, 2025 at 19:26

    … [Trackback]

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

  5. Thai restaurant Oregon Says:
    April 19th, 2025 at 13:57

    … [Trackback]

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

  6. heng678 Says:
    May 8th, 2025 at 20:13

    … [Trackback]

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

  7. pinco indir Says:
    May 15th, 2025 at 21:32

    … [Trackback]

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

  8. เครื่องเป่าแอลกอฮอล์ Says:
    May 17th, 2025 at 01:53

    … [Trackback]

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

  9. exchange xmr without id Says:
    May 17th, 2025 at 07:04

    … [Trackback]

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

  10. essentials Says:
    May 22nd, 2025 at 22:09

    … [Trackback]

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

  11. kinderpark holland Says:
    May 23rd, 2025 at 17:16

    … [Trackback]

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

  12. pinco Says:
    May 24th, 2025 at 12:55

    … [Trackback]

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

  13. ระบบจัดการออเดอร์ Says:
    May 29th, 2025 at 21:24

    … [Trackback]

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

  14. เน็ตบ้าน ais Says:
    June 5th, 2025 at 18:38

    … [Trackback]

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

Comments