0

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 [email protected]
    DocumentRoot /usr/local/www/mydomain.tld

</VirtualHost>
<VirtualHost reports.mydomain.tld>
    ServerName reports.mydomain.tld
    ServerAlias reports.mydomain.tld 
    ServerAdmin [email protected]
    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]

3 Answers 3

4

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 [email protected]
    DocumentRoot /usr/local/www/reports.mydomain.tld/app/webroot
</VirtualHost>

<VirtualHost *:80>
    ServerName mydomain.tld
    ServerAlias *.mydomain.tld
    ServerAdmin [email protected]
    DocumentRoot /usr/local/www/mydomain.tld
</VirtualHost>
0

I would recommend the following:


<VirtualHost mydomain.com:80>
  ServerName mydomain.com
  ServerAdmin [email protected]

  AddType application/x-httpd-php .php

  DocumentRoot /path/to/my/app/
  <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
  </FilesMatch>

  RewriteEngine On
  RewriteRule (.*)-cb\d+\.(.*)$ $1.$2 [L]

  <Directory "/path/to/my/app/">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
-1

Put

<VirtualHost reports.mydomain.tld>
    ServerName reports.mydomain.tld
    ServerAlias reports.mydomain.tld 
    ServerAdmin [email protected]
    DocumentRoot /usr/local/www/reports.mydomain.tld/app/webroot/

</VirtualHost>

above

<VirtualHost mydomain.tld:80>
    ServerName mydomain.tld
    ServerAlias *.mydomain.tld
    ServerAdmin [email protected]
    DocumentRoot /usr/local/www/mydomain.tld

</VirtualHost>

Should do the trick :)

3
  • The first argument of VirtualHost should be representative of HOW your site is accessed (i.e. the IP makes more sense). If you have not named this argument as a NameVirtualHost previously and it isn't sitting on it's own IP, then you're going to have unexpected results. Re-ordering doesn't fix the problem I'm afraid. Dan C's answer is a much better fix. Sep 4, 2009 at 10:55
  • In the end reordering fixes it. And yea i wasn't careful on reading that he set it up as domains not ip's, but apache processes directives in the order it reads them, so reordering IS the fix in the end, not changing the domains to IP's.
    – sh1ny
    Sep 4, 2009 at 10:59
  • 1
    In the end, i used a combination of both suggestions from you guys. i.e. 1) Changed the NameVirtualHost to be a wildcard 2) moved the reports.mydomain.tld virtualhost config above the *.mydomain.tld virtualhost config Eventually, my final config looked like this NameVirtualHost *:80 <VirtualHost *:80> ServerName reports.mydomain.tld ServerAdmin [email protected] DocumentRoot /usr/local/www/reports.mydomain.tld/app/webroot </VirtualHost> <VirtualHost *:80> ServerName mydomain.tld ServerAlias *.mydomain.tld DocumentRoot /usr/local/www/mydomain.tld </VirtualHost>
    – user19384
    Sep 4, 2009 at 12:30

You must log in to answer this question.