I'm using Apache/2.4.10 (Win32) and I have a question about the relation between SERVER_NAME
and HTTP_HOST
.
I have noticed a strange(at least I think) behavior of apache, inside my httpd.conf
I have:
ServerName example.com:80
Now as I tested via PHP
server variables which are taken from apache.
From php(the link above):
If the script is running on a virtual host, this will be the value defined for that virtual host.
I'm not using any virtual hosts.
SERVER_NAME
overridden by HTTP_HOST
, for example if I will access the website via m.example.com
the SERVER_NAME
is overriden by the HTTP_HOST
and the both be equal to the same value, now in spite it has been tested I wanted to know:
- Does apache using any virtual host without me knowing about it, here is my httpd.conf file?
- Is it
PHP
or apache behavior? - Is it done automatically(the override) by
PHP
or Apache(at this point I don't know who's guilty)?
Edit:
- The override is done by apache, I've tested using
.htaccess
file, the result is that even before the variables delivered toPHP
the override is done.
So the override is done by apache, the only question remain is what are the conditions for such override and more important is there a way to get or a variable that provide the ServerName
value from the httpd.conf
?
If you want to track down possible virtual names and/or rewrites, a couple of place to check: 1) ports.conf ('NameVirtualHost' is defined there); 2) .htaccess file.
But, I think the more correct'ish answer to your question is the relation. ServerName is the default name apache server is calling itself. This name does not necessarily require a matching DNS record as a local /etc/hosts entry will keep Apache from complaining.
HTTP_HOST on the other hand, is the name the client (browser) knows the server as, which to be accessible, must have a matching DNS entry (or a matching hosts entry on the client) to be able to resolve and be accessible.
In this context, HTTP_HOST will always appear in Apache request logs because the client does not know any other name for the server other than the HTTP_HOST it requested.
FOLLOW-UP: The usage of FINDSTR is:
findstr "string_to_find" path_to_file
Below is a sample dos batch file (script) that uses FINDSTR to find the line that says "ServerName" in httpd.conf. This batch script also parses the line it finds and echoes (i.e. prints to the screen) only the value of the ServerName variable, not the whole line.
@echo off for /f "tokens=2* delims==" %%i in ('FINDSTR "ServerName" httpd.conf') do ( echo %%i )
You can edit the word 'httpd.conf' and specify the full path, as needed.