A reverse proxy server forwards requests to an internal application server. The proxy server has its HTTP_HOST
value set to the hostname used the access the site, e.g.: www.example.com
or www.alias2.com
or www.alias3.com
.
The internal server receives requests to its internal IP address, so its HTTP_HOST
value is set to: 192.168.64.2
.
How can the internal application server determine which domain name was used for the Host:
in the original http request?
It would be possible to configure the SERVER_NAME
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?
Looking at all environment variables available to Apache on the application server, none indicate the requested hostname except HTTP_REFERER
(which obviously can't be relied upon):
[HTTP_HOST] => 192.168.64.2:80
[SERVER_NAME] => 192.168.64.2
[REMOTE_ADDR] => 192.168.64.1
[SERVER_ADDR] => 172.19.0.3
[SCRIPT_URI] => http://192.168.64.2:80/index.php
[HTTP_REFERER] => http://www.example.com/prev/
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.