title: PHP $_SERVER[‘SERVER_ADDR’] variable always returns 127.0.0.1
body: <p>We have multiple load-balanced webserver machines running the same PHP webapp (<a href="http://en.wikipedia.org/wiki/LAMP_(software_bundle)" rel="nofollow noreferrer">LAMP</a>) and I'd like to run slightly different code on each server (<em>for testing purposes</em>). I was hoping to use the <code>$_SERVER['SERVER_ADDR']</code> super global to do something like this:</p>
  
  <pre><code>if ($_SERVER['SERVER_ADDR'] == 'XXX.XXX.XXX.XXX') {
    echo "Do one thing";
  } elseif ($_SERVER['SERVER_ADDR'] == 'YYY.YYY.YYY.YYY') {
    echo "Do something else";
  }
  </code></pre>
  
  <p>Unfortunately, this doesn't work because both machines are setting <code>$_SERVER['SERVER_ADDR']</code> to '<strong>127.0.0.1</strong>'. How can I configure them so that <code>$_SERVER['SERVER_ADDR']</code> is set to their public IP address?</p>
  
  <p>I'm guessing the issue may be something to do with <code>/etc/hosts</code> so for refererence it currently looks like this:</p>
  
  <pre><code>127.0.0.1       localhost.localdomain localhost
  ::1             localhost6.localdomain6 localhost6
  XXX.XX.XX.XX    blahblah
  </code></pre>
  
  <h2>Update...</h2>
  
  <p><strong>Oops</strong>! I neglected to consider the <a href="http://en.wikipedia.org/wiki/Nginx" rel="nofollow noreferrer">nginx</a> reverse proxy in front of the web servers. All the traffic to those web servers arrives from nginx due to the following line in the nginx conf:</p>
  
  <pre><code>location / {
      root                  /var/www/staging/current;
      proxy_pass            http://localhost:8880;
  }
  </code></pre>