Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Apache typically will pick the first virtual host whose <code>ServerName</code> or <code>ServerAlias</code> matches the host name provided in the <code>Host</code> HTTP header. In your case, since you have no <code>ServerName</code> directives, Apache supposedly uses a reverse DNS lookup on the IP address to fake a server name, and presuming that the reverse DNS leads to domain.com, which doesn't match, Apache then defaults to the first virtual host. Sounds complicated, I know... the bottom line is, you should use <code>ServerName</code> and <code>ServerAlias</code> to make the configuration explicit. Try something more like this:</p> <pre><code>NameVirtualHost 127.0.0.1 &lt;VirtualHost 127.0.0.1&gt; ServerName domain.com ServerAlias www.domain.com VirtualDocumentRoot /var/www/%0 &lt;/VirtualHost&gt; &lt;VirtualHost 127.0.0.1&gt; ServerName sub.domain.com ServerAlias *.domain.com VirtualDocumentRoot /var/www/%2.%3_%1 &lt;/VirtualHost&gt; </code></pre> <p>That should use <code>/var/www/domain.com</code> for <a href="http://domain.com" rel="noreferrer">http://domain.com</a> and <code>/var/www/www.domain.com</code> for <a href="http://www.domain.com" rel="noreferrer">http://www.domain.com</a>, both of which are served by the first vhost, and <code>/var/www/sub.domain.com</code> for <a href="http://sub.domain.com" rel="noreferrer">http://sub.domain.com</a>, <code>/var/www/blah.domain.com</code> for <a href="http://blah.domain.com" rel="noreferrer">http://blah.domain.com</a>, and so on.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload