How to keep global ServerName in apache working?

Viewed 7

The apache documentation is a bit unclear on vhost configuration. Where I normally use wampserver I discovered a discrepancy with xampp. Consider the fairly standard httpd.conf in the xampp distribution containing amonng other things

ServerName localhost:80
 
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
</Directory>

And a empty httpd-vhosts.conf. Everything works as advertised and the content of the xamp/htdocs folder is used (and redirects to /htdocs/dashboard)

As soon as a section is added to httpd-vhosts.conf for instance

<VirtualHost *:80>
    ServerName customer01.localhost

    DocumentRoot "D:/Customers/Customer01/httpdocs"
    <Directory  "D:/Customers/Customer01/httpdocs">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

and the proper amendments are made to .../etc/hosts http://localhost stops working as it now redirects to D:/Customers/Customer01/httpdocs ignoring the ServerName setting in httpd.conf.

Is this by design?

If, however, in addition to the ServerName setting in httpd.conf the following is added to httpd-vhosts.conf:

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "C:/xampp/htdocs"
  <Directory "C:/xampp/htdocs/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

things are fine again.

Question: why is the extra vhost needed as global ServerName are already set in httpd.conf? Is this something the ApacheFriends should add to vhost by default?

0 Answers
Related