Wildcard sub domains?

Posted February 21, 2013 20.4k views
Hi there, can anyone explain to me exactly what I need to do to set up sub domains / wildcard sub domains? ie. What I need to do to the DNS and Apache? Thanks in advance, Francis PS. On an ubuntu vps

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers
If you're not using a control panel, then you'd simply create an A entry using * as the entry instead of a name and then setup *.yourdomain.ext in your Apache vhost configuration.

So for your vhost, something such as the following should get you going.

DocumentRoot /path/to/home/folder
ServerAlias *.yourdomain.ext
ServerName www.yourdomain.ext
CustomLog domlogs/yourdomain.ext combined

The ServerName & ServerAlias are what you want to pay attention to. The ... are just in there for separation and should *not* be added to your vhost configuration.

For your WildCard DNS entry, it should look something like:

*.yourdomain.ext. 14400 IN A

- OR -

* 14400 IN A

It depends on how your registrar allows you to enter DNS records.
Im thinking you just setup DNS and then you just need to tell apache the different sites with virtualhosts