WordPress – Setting up WordPress MU, wildcard dns and apache virtual hosts

apache-2.2domain-name-systemWordpress

I manage a server that runs WordPress MU. The different blogs hosted on the server are accessible as subdomains, e.g. blog1.mydomain.tld, blog2.mydomain.tld, etc.

I also need to run a custom application (reports.mydomain.tld) using the same server.

My virtual host configuration is as follows:

NameVirtualHost mydomain.tld:80
<VirtualHost mydomain.tld:80>
    ServerName mydomain.tld
    ServerAlias *.mydomain.tld
    ServerAdmin admin@mydomain.tld
    DocumentRoot /usr/local/www/mydomain.tld

</VirtualHost>
<VirtualHost reports.mydomain.tld>
    ServerName reports.mydomain.tld
    ServerAlias reports.mydomain.tld 
    ServerAdmin admin@mydomain.tld
    DocumentRoot /usr/local/www/reports.mydomain.tld/app/webroot/

</VirtualHost>

When I try to access the subdomain reports.mydomain.tld, WordPress [remainder of text missing]

Best Answer

I'd advise against using hostnames in your VirtualHost and NameVirtualHost directives. Instead either use IP addresses or wildcards.

Additionally when NameVirtualHost'ing and a requested hostname could match either vhost, then the first vhost encoutered takes preference. In your case this would mean that the wildcard catches all.

You can also remove the extraneous ServerAlias.

Try instead:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName reports.mydomain.tld
    ServerAdmin admin@mydomain.tld
    DocumentRoot /usr/local/www/reports.mydomain.tld/app/webroot
</VirtualHost>

<VirtualHost *:80>
    ServerName mydomain.tld
    ServerAlias *.mydomain.tld
    ServerAdmin admin@mydomain.tld
    DocumentRoot /usr/local/www/mydomain.tld
</VirtualHost>
Related Topic