Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Before I start I'd like to say that I've already read relevant questions here on serverfault but I couldn't find a solution.

Here's my problem. I'm using a third party DNS and I've added a wildcard A record * which points to my server's ip address. The problem I'm having with that is that every non existent sub-domain points to that do exist work fine). I'd like to note that the apache website configuration for is not the default one (000-default.conf) but a separate one ( That's what I can't understand. The non-existent subdomains should point to the default configuration file, shouldn't they?

Here is part of

SuexecUserGroup "#1003" "#1004"
DocumentRoot /home/biglle/public_html
ErrorLog /var/log/virtualmin/biglle.com_error_log
CustomLog /var/log/virtualmin/biglle.com_access_log combined
ScriptAlias /cgi-bin/ /home/biglle/cgi-bin/
ScriptAlias /awstats/ /home/biglle/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/biglle/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/biglle/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/biglle/fcgi-bin/php5.fcgi .php5
<Directory /home/biglle/cgi-bin>
allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
AuthName " statistics"
AuthType Basic
AuthUserFile /home/biglle/.awstats-htpasswd
require valid-user
Alias /dav /home/biglle/public_html
Alias /pipermail /var/lib/mailman/archives/public
<Location /dav>
DAV on
AuthType Basic
AuthName ""
AuthUserFile /home/biglle/etc/dav.digest.passwd
Require valid-user
ForceType text/plain
Satisfy All
RemoveHandler .php
RemoveHandler .php5
RewriteEngine off
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*)$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*)$1.cgi$3
php_value memory_limit 32M

Currently I'm using a php hack that checks if the domain name has a respective .conf file in /etc/apache2/sites-enabled/ and if it doesn't it displays a 404 error but that's obviously not a permanent solution. Also this hack only works for the index page of each subdomain.

Due to me not having more than 10 rep I can't post examples here. You can see them on this paste here:

EDIT: apache2ctl -S output

root@biglle:/# apache2ctl -S
[Sun May 27 22:00:11 2012] [warn] NameVirtualHost has no VirtualHosts
VirtualHost configuration:        is a NameVirtualHost
         default server (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/       is a NameVirtualHost
         default server (/etc/apache2/sites-enabled/
         port 443 namevhost (/etc/apache2/sites-enabled/
wildcard NameVirtualHosts and _default_ servers:
*:80          (/etc/apache2/sites-enabled/000-default:1)
Syntax OK
share|improve this question
Can you provide the output of apache2ctl -S? – Shane Madden May 27 '12 at 18:52
I'll edit it in the question. – Constantine Loukas May 27 '12 at 19:01

2 Answers 2

up vote 4 down vote accepted

Apache will look for VirtualHosts in the following order:

  1. First defined VirtualHost with matching IP, port, and ServerName
  2. First defined VirtualHost with matching IP and port
  3. First defined VirtualHost with wildcard (or _default_) IP and matching port

I'm assuming that the server only has one IP address, namely        is a NameVirtualHost
    default server (/etc/apache2/sites-enabled/
wildcard NameVirtualHosts and _default_ servers:
    *:80          (/etc/apache2/sites-enabled/000-default:1)

Incoming requests on which don't match a ServerName will therefore use the VirtualHost defined in (because that is the first VirtualHost which matches the IP and port). The VirtualHost in 000-default will only be used for requests received on an IP other than

Unless you're actually doing IP based virtual hosting, I suggest that you change all your VirtualHosts to not specify an IP address (i.e. <VirtualHost *:80>), and make sure that the one you want to be the default is listed first in the configuration (which the 000-default file should do).

share|improve this answer
You can't imagine how long I've been looking for a fix to that problem. Thanks a million! – Constantine Loukas May 27 '12 at 20:44

Additional tips:

  1. On some browsers (e.g. google chrome) you will only be able to browse and see the results of your apache config changes after restarting the browser.
  2. Search for Redirect directives in the config files - they may also cause an issue.


share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.