Setting up Ubuntu Server on Amazon EC2 for hosting multiple domains with wildcard subdomains
- by Ashish Kumar
I'm trying to set up multiple domains on my Amazon EC2 micro instance running Ubuntu Server 12.04. I installed Apache correctly and set up virtual hosts but having problems with wildcard subdomains.
This is what my httpd.conf file looks like
NameVirtualHost *:80
<VirtualHost *:80>
UseCanonicalName Off
VirtualDocumentRoot /home/username/domains/%0/html/
</VirtualHost>
My DNS records (on Amazon Route 53) are:
domain.tld A 1.2.3.4
*.domain.tld A 1.2.3.4
If i create a test.domain.tld directory with the html subdirectory, it works fine. But what I want to do is to redirect *.domain.tld to domain.tld in case there is no directory for the sub-domain accessed. I would also like www.domain.tld to redirect to domain.tld. The system should also work if I decide to host another website, example.com, on the server.
I tried Googling a lot but without any luck. Suggestions?