Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]

share|improve this question

migrated from stackoverflow.com Sep 4 '09 at 10:38

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 4 down vote accepted

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>
share|improve this answer

I would recommend the following:


<VirtualHost mydomain.com:80>
  ServerName mydomain.com
  ServerAdmin admin@mydomain.com

  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>
share|improve this answer

Put

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

above

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

</VirtualHost>

Should do the trick :)

share|improve this answer
    
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. –  Philip Reynolds Sep 4 '09 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 '09 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 admin@mydomain.tld 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 '09 at 12:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.