Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a modified VirtualHost setting from my server.

<VirtualHost *:80>

  DocumentRoot /mnt/example/public

  <Directory /mnt/example/public>
    AllowOverride all
    Options -MultiViews


I found that I can access the and also *, e.g.,, etc.

I know there should be a ServerAlias setting which let me activate wildcard subdomain suppot. But I can't see the ServerAlias setting my VirtualHost or Apache config file.

I want to allow only and can access my site, and other subdomain will get a 404 error.

How can I set this up?

Thanks all. :)

share|improve this question
up vote 3 down vote accepted

I think what you're missing before all your vhost containers in the conf file is:

NameVirtualHost *:80

Once you've done that, depending on what you want to do for all those wildcards you deem "invalid" you can create the required <virtualhost> containers, and then followup with a final one with a wildcard that acts a catchall for the rest.


For instance, what I've done is have a vhost container for myhost.mydomain.tld, and then whatever other domains, and finally, I have a container for *.mydomain.tld that basically points to a static page notifying people to mind their own business.

share|improve this answer
Thanks. After I added NameVirtualHost *:80, the apache give me a warning when I restart it. "NameVirtualHost *:80 has no VirtualHosts". But your last solution is great, I will just create a static page for that. Thanks :) – Victor Lam Oct 26 '11 at 12:58

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.