3

Using Ubuntu 18.04

I have my main website www.example.com, all the files are hosted in /var/www/html/ and it works as expected. I would now like to make a new website in a subdomain www.blog.example.com.

I created a new dns record for the subdomain on my web host and have confirmed that it's working, when I ping www.blog.example.com I see the correct server IP address.

My directory structure looks like this;

  • /var/www/html (contains all files for www.example.com)
  • /var/www/blog.example.com (contains single index.html file for testing)

I have virtual hosts for each domain, contents are below;

/etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html
    <Directory /var/www/html/rascal.ac.uk>
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Include conf-available/serve-cgi-bin.conf
</VirtualHost>

/etc/apache2/sites-available/blog.example.com.conf

<VirtualHost *:80>
    ServerName blog.example.com
    DocumentRoot /var/www/blog.example.com
    <Directory /var/www/blog.example.com/>
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

There's also /etc/apache2/sites-available/000-default.conf looks like this;

<VirtualHost *:80>
    DocumentRoot /var/www/html
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

All sites are enabled and I have reloaded / restarted apache multiple times.

When I visit www.example.com I see my main website, as expected. When I visit www.blog.example.com I see my main website also, I should be seeing the contents on my index.html file.

If I disable 000-default.conf both urls display the contents of blog.example.com, could the issue be in this file?

1

You have

ServerName blog.example.com

but that's a different name from www.blog.example.com. So Apache doesn't use that VirtualHost. It falls back to the default VirtualHost instead. Adding

ServerAlias www.blog.example.com

should fix it. See ServerAlias.

Of course these are example names. If that doesn't fix it, please edit your question to show the real hostnames.

1
  • Thanks for this and the explanation! – TheOrdinaryGeek Feb 19 at 11:29

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.