How to setup subdomain on multiple virtual host vps?

September 3, 2015 3.9k views
Apache

I'm on an ubuntu server and using apache.
I've set several domains on my droplet but when I tried to access www.seconddomain.com it is redirected to firstdomain.com, as so the other nextdomain.com.

without any CNAME I can access the other sites normally. But then I want to create an A record type subdomain, test.firstdomain.com to access root directory /var/www/test. And its the same problem again, it shows the page of firstdomain.com.

My setting is,

www.firstdomain.com. 1800 IN CNAME firstdomain.com.
*.codemastery.net. 1800 IN CNAME codemastery.net.
test.firstdomain.com. 1800 IN A 128.199.81.1

for the conf file I am creating new file on sites-available test.firstdomain.com.conf then add it with a2ensite..

Any help is appreciated, thanks

2 Answers

Take a look at your apache.conf (CentOS: httpd.conf), located in /etc/apache2/conf or /etc/httpd/conf. Almost at the end file you will find something about VirtualHost (NameVirtualHost to be precise). Perhaps this is still commented? If so, please uncomment en restart apache.

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
Have another answer? Share your knowledge.