Reverse Proxy Visitors IP

August 22nd, 2013

Reverse Proxy Visitors IPWhen using a reverse proxy service the server variable REMOTE_ADDR no longer contains the visitor’s IP address and contains the reverse proxy service ip address which is correct. Programmers often (not always) key off this variable for the visitors IP which isn’t correct in this instance. As a result location services, ip logging, and other things will not be recording the proper IP address.

This plugin updates the server variable REMOTE_ADDR early on in processing to contain the visitor’s original IP address so any extension that keys off this variable will have the correct IP address to work with. The variable HTTP_X_FORWARDED_FOR will be used to fix REMOTE_ADDR to be correct and contain the visitors IP. HTTP_X_FORWARDED_FOR is populated when using a reverse proxy service so any service should be covered.

Whether you are on shared hosting and cannot install the necessary web server modules or you just aren’t interested in doing any modifications to your web server on VPS/Dedicated you can use this plugin effortlessly. Just install, enable it, and use the defaults or configure some of the options.

Cloudflare is an example of a reverse proxy service with CDN, performance, and security benefits and they offer free and paid accounts (but there are others). It doesn’t matter which provider you use for this service just make sure your name servers for your domain point to theirs and the ip ranges match what your provider has.

Note: Try publishing this plugin to the be the first plugin running (plugin order) in case other extensions try to make use of the IP, this will ensure it is always correct.

-Enable/Disable running in admin section
-Toggle modifying REMOTE_ADDR or not
-Toggle warning to indicate traces of reverse proxy not found or IP fixed already
-Toggle details for debugging to output both REMOTE_ADDR and HTTP_X_FORWARDED_FOR
-Specify IP ranges so if you switch providers or ranges change you can manually enter them and be up to date (default values are cloudflare as of aug/2013, but you can manually enter or modify any ranges)

This is not an official cloudflare product and is not affiliated with them in any way. This plugin can be used with ANY reverse proxy service.