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

I'm having a strangely difficult time setting up a subdomain (x.example.com). The main site works fine, but I get 404 errors attempting to hit x.example.com no matter how I set up the VirtualHost config.

NameVirtualHost *:80
<VirtualHost *:80>
 ServerName www.example.com
 DocumentRoot /var/www/example.com/htdocs
 ServerAlias example.com

<VirtualHost *:80>
    ServerName x.example.com
    ErrorLog /var/logs/x-error-log
    CustomLog /var/logs/x-access-log common
    DocumentRoot /var/www/x/htdocs

As far as I can tell, this is a vanilla set up. Any suggestions would be appreciated.

share|improve this question
does the directory on DocumentRoot exist ? what /var/log/x-error-log tell you ? what /var/log/httpd/error_log tell you ? –  Prix Aug 31 '10 at 0:13
The directory exists. As a test, when I leave out the first entry (www.example.com), apache treats x.example.com as the default, and 'finds' it correctly. The only entries in the log files are from this test; otherwise, it's 404 all the way. Is there a specific apache config option (module or ??) that needs to be on or off for virtual hosts to work in this way? –  Aaron Aug 31 '10 at 0:34
Do you have your SOA records registered properly for your subdomain names? –  Mies Aug 31 '10 at 10:14

3 Answers 3

My guess is that access is not allow to the DocumentRoot for the new VirtualHost. You need to add something like the following to your Virtualhost setting.

<Directory "/var/www/x/htdocs">
    Options Includes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

By default, access to the filesystem is denied; you likely have something like this somewhere in your config file(s):

<Directory "/">
    Options FollowSymLinks
    AllowOverride None
    order allow,deny
    deny from all

Hope this helps

share|improve this answer
That didn't fix it either. The new config looks like this: <VirtualHost *:80> ServerName x.example.com ErrorLog /var/logs/x-error-log CustomLog /var/logs/x-access-log common DocumentRoot /var/www/x/htdocs <Directory "/var/www/x/htdocs"> Options -Indexes FollowSymLinks MultiViews AllowOverride All Allow from all </Directory> </VirtualHost> –  Aaron Aug 31 '10 at 3:50
Can you look at /var/logs/x-access-log and confirm that you are indeed accessing the correct virtualhost when you access x.example.com? Then look at the corresponding line in /var/logs/x-error-log which could explain why the 404. –  Urgoll Aug 31 '10 at 15:34

Try adding Alias x /var/www/x/htdocs to your main site. This will enable you to see the x content from your main site if it is available.

404 often occurs if the directories or files can not be read. Check directory permission on the file system. The directories need permission like 755 or 750 depending on the group. Files need permissions like 644 or 640 depending on the group. Generally the web server's id (opten apache or www-data) should not own the content. It is common to set the group on the content to the web server's group.

Check the directory permission configuration. If it is for /var/www, then both site are covered. If it is for /var/www/htdocs, either setup a copy for /var/www/x/htdocs, or change it to /var/www.

Consider setting the group sticky bit on /var/www/x/htdocs, and doing a recurcive chgrp on it.

share|improve this answer

Just to check:

Create an A record in your DNS configuration for your subdomain to resolve to your IP address.

share|improve this answer

Your Answer


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