The MU forums have moved to WordPress.org

Recognizing the correct Remote IP address w/load balancer? (3 posts)

  1. prwood
    Member
    Posted 14 years ago #

    I am setting up a WordPress MU installation running on two web servers behind a load balancer. Whenever an email is generated to notify us of a new registration, it says that the remote IP address is the address of the load balancer rather than the original source IP address.

    In investigating this issue, I have found that WordPress MU is using the $_SERVER['REMOTE_ADDR'] environment variable to obtain this IP address. I also know that our load balancer sets its own environment variable (let's call it $_SERVER['LOAD_BAL_IP'] for obfuscation purposes) that contains the actual source IP. What I do not know is if there is an easy way to tell WordPress to use this environment variable instead of the REMOTE_ADDR to generate the IP address for these notification emails.

    I have found various places in WPMU code where REMOTE_ADDR is used, and one obvious solution would be to simply change each of them to LOAD_BAL_IP. However, this would require a hack to WPMU core code, and would have to be reinstated each time I did an upgrade.

    I have also tried modifying the index.php script in both the root level /wordpress/ directory and the one in /wp-admin/ to include a statement like this:

    $_SERVER['REMOTE_ADDR'] = $_SERVER['LOAD_BAL_IP'];

    ... but it doesn't seem to stick for some reason.

    Can anybody think of a solution that would work?

  2. prwood
    Member
    Posted 14 years ago #

    I ended up solving this by putting the definition at the BOTTOM of wp-config.php. Previously I had tried putting it at the TOP of wp-config.php and at the TOP of the index.php scripts, which apparently doesn't work.

    Weird. Wondering if someone can explain *why* that worked.

  3. tdjcbe
    Member
    Posted 14 years ago #

    *shrug* Only thing I can think of is it needing that include of wp-settings.php for some reason.

    edit: A couple minutes of google'ing finds a number of folks mentioning load balancing but only two real discussions:

    http://wordpress.org/support/topic/147992
    http://barry.wordpress.com/2008/04/28/load-balancer-update/

    OK 3: http://tech.nocr.at/tech/how-to-speed-up-wordpress-with-nginx-and-wp-super-cache/

About this Topic