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 webmaster@example.com
    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 webmaster@example.com
    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
  • 1
    The obvious questions are: did you restart apache after checking the configuration with apachectl configtest ; did you place an IndexDocument in the DocumentRoot of the subdomain; which virtual hosts are shown by apachectl -S ? And IIRC writing to the same log files from within two different VirtualHost entries is a no no. – HBruijn Jul 7 '14 at 19:18
  • are both sites linked in /etc/apache2/sites-enabled i.e. did you run a2ensite sub? – HBruijn Jul 7 '14 at 19:21
  • Thanks for the assist. I have edited my question, and have added the info you've enquired about. I have added both sites, yes. – Odyss3us Jul 7 '14 at 20:28

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.

| improve this answer | |
  • Thanks Michael, I had a look at 000-default.conf, all that was defined was ServerAdmin, DocumentRoot, ErrorLog and CustomLog. It was pointing to the apache test page though, and after commenting everything out, disabling 000-default with a2dissite 000-default and restarting apache, it seems to be working, thanks for the assist! :) – Odyss3us Jul 7 '14 at 20:41

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.