Ubuntu subdomain not working

Odyss3us asked:

I’m trying to set up a subdomain with Apache2 on my Ubuntu droplet, I’ve followed this tutorial to the T but every time I navigate to my subdomain, I get the default apache landing page.

So I’ve set up separate conf files for both my main and sub domains,


<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/mainsite/public_html
    ServerName www.example.com
    ServerAlias example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/submainsite/public_html
    ServerName sub.example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

What am I doing wrong? I don’t have much server side experience, so please pardon my ignorance on the matter.


Both sites are linked, I did run a2ensite.

When running apachectl -S I get:

 default server sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
 port 80 namevhost sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
 port 80 namevhost sub.example.com (/etc/apache2/sites-enabled/sub.conf:1)
 port 80 namevhost www.example.com (/etc/apache2/sites-enabled/mainsite.conf:1)
         alias example.com

My answer:

You defined the default server in 000-default.conf as sub.example.com and it is pointed to the Apache test page. Because it comes first, it overrides the second sub.example.com virtual host you had defined in sub.conf.

To fix the problem, edit 000-default.conf and remove ServerName sub.example.com from it.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.