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: HTTP (Internet), Linux | 15 Comments »

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

  1. Buy CZ pistols Says:
    April 7th, 2022 at 20:31

    … [Trackback]

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

  2. Firearms For Sale Says:
    April 11th, 2022 at 07:21

    … [Trackback]

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

  3. sbo Says:
    May 28th, 2022 at 18:43

    … [Trackback]

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

  4. https://krajowy.biz/ Says:
    June 8th, 2022 at 22:12

    … [Trackback]

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

  5. medical marijuana for sale, Says:
    July 2nd, 2022 at 05:58

    … [Trackback]

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

  6. nova88 Says:
    July 15th, 2022 at 04:46

    … [Trackback]

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

  7. ตัดกราม Says:
    July 18th, 2022 at 19:59

    … [Trackback]

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

  8. Turanabol Says:
    July 24th, 2022 at 17:34

    … [Trackback]

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

  9. sbobet Says:
    July 30th, 2022 at 03:08

    … [Trackback]

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

  10. แทงบอลโลก 2022 Says:
    August 8th, 2022 at 17:41

    … [Trackback]

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

  11. sbo Says:
    August 30th, 2022 at 18:57

    … [Trackback]

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

  12. จำนองที่ดิน Says:
    October 2nd, 2022 at 13:59

    … [Trackback]

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

  13. สินเชื่อด่วน Says:
    October 10th, 2022 at 09:07

    … [Trackback]

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

  14. เงินด่วนออนไลน์ Says:
    October 30th, 2022 at 12:45

    … [Trackback]

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

  15. magic mushrooms legal for sale Says:
    November 6th, 2022 at 11:36

    … [Trackback]

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

Comments