1

This is a modified VirtualHost setting from my server.

<VirtualHost *:80>

  ServerName example.com
  DocumentRoot /mnt/example/public


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

</VirtualHost>

I found that I can access the example.com and also *.example.com, e.g. www.example.com, abcde.example.com, 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 www.example.com and example.com can access my site, and other subdomain will get a 404 error.

How can I set this up?

Thanks all. :)

3

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.

See http://httpd.apache.org/docs/2.2/vhosts/name-based.html

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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