title: How to get reverse proxy’s HTTP_HOST from internal application server
body: <p>A reverse proxy server forwards requests to an internal application server. The proxy server has its <code>HTTP_HOST</code> value set to the hostname used the access the site, e.g.: <code>www.example.com</code> or <code>www.alias2.com</code> or <code>www.alias3.com</code>.</p>
  
  <p>The internal server receives requests to its internal IP address, so its <code>HTTP_HOST</code> value is set to: <code>192.168.64.2</code>.</p>
  
  <p>How can the internal application server determine which domain name was used for the <code>Host:</code> in the original http request? </p>
  
  <p>It would be possible to configure the <code>SERVER_NAME</code> to the hostname used by the application, but if many different hostname aliases have access to the website how can we know which one was used? </p>
  
  <p>Looking at all environment variables available to Apache on the application server, none indicate the requested hostname except <code>HTTP_REFERER</code> (which obviously can't be relied upon):</p>
  
  <pre><code>[HTTP_HOST] =&gt; 192.168.64.2:80
  [SERVER_NAME] =&gt; 192.168.64.2
  [REMOTE_ADDR] =&gt; 192.168.64.1
  [SERVER_ADDR] =&gt; 172.19.0.3
  [SCRIPT_URI] =&gt; http://192.168.64.2:80/index.php
  [HTTP_REFERER] =&gt; http://www.example.com/prev/
  </code></pre>
  
  <p>I'm aware some reverse proxys can be configured to forward the hostname used in the original request. I'm asking the question in general terms because I would like to know if there is a solution that isn't proxy-specific. At the moment I'm using BrowserSync as the reverse proxy during development, which doesn't appear to have a way to forward the http host, and in any case, I'd like to be able to design my application so that it doesn't rely on the reverse proxy providing this information. </p>