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)?


  • The override is done by apache, I've tested using .htaccess file, the result is that even before the variables delivered to PHP 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.

  • Andrew, please check my edit, and can you give me an example for how apache will complain, because after I changed the ServerName I didn't find any log for complaning at all, can you show me how apache complain and maybe help me with example for how would you solve it editing the hosts file. Sep 23 '14 at 16:53
  • Hi Aviel, Apache often does not complain about 'ServerName' because the name is arbitrary, meaning it is allowed to be anything you want it to be. For instance, you might just call it web01 or web02 for internal purposes. ServerName has nothing to do with HTTP_HOST, the name used by clients to access the server. Apache might complain about ServerName on start up if it conflicts with an existing/different DNS or local hosts file entry. Complaints, if any, are logged in the Apache error log (e.g. error_log, error.log, or whatever naming convention you are using to log Apache errors).
    – Andrew S
    Sep 23 '14 at 19:41
  • As for "is there a way to get or a variable that provide the ServerName value from the httpd.conf?" What process or client needs this variable? Does the http client (browser) need it? Does a local server daemon need it? For what purpose? I ask because, on Windows, you can use a dos command like 'findstr ServerName C:\path_to_apache.conf' and it will print the line with ServerName in it, thus with a little extra processing in a dos batch file (or power shell if you prefer) you can create a variable from it.
    – Andrew S
    Sep 23 '14 at 20:01
  • Can you show me how would you use of findstr... Sep 24 '14 at 7:53
  • I can't write readable code in a comment, so re-read my answer above....
    – Andrew S
    Sep 24 '14 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.