Apache showing default page for http://domain but not for https://domain or http://www.domain

My domain is: josvlaar.com
My web server is Apache 2, OS is Ubuntu 24.04.

When navigating to http://josvlaar.com, my default apache page is shown. But when navigating to http://www.josvlaar.com or to https://josvlaar.com, my actual website is shown with https enabled. This is my Apache configuration (generated partially by certbot):

josvlaar.com.conf:
<VirtualHost *:80>
    ServerName josvlaar.com
    ServerAlias www.josvlaar.com
    ServerAdmin email

    DocumentRoot /var/www/josvlaar

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/josvlaar/>
        AllowOverride All
    </Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =josvlaar.com [OR]
RewriteCond %{SERVER_NAME} =www.josvlaar.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
josvlaar.com-le-ssl.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName josvlaar.com
    ServerAlias www.josvlaar.com
    ServerAdmin email

    DocumentRoot /var/www/josvlaar

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/josvlaar/>
        AllowOverride All
    </Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/josvlaar.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/josvlaar.com/privkey.pem
</VirtualHost>
</IfModule>

I'm puzzled as to why http://www.josvlaar.com would redirect to https://josvlaar.com but http://josvlaar.com would not. I'm also puzzled as to why https://josvlaar.com would show my site but http://josvlaar.com would show the Apache default landing page.

Anybody have an idea?

There's probably another virtualhost lingering somewhere in Apache. Please show the output of:

apachectl -t -D DUMP_VHOSTS
2 Likes

For some reason, the 000-default config file was enabled for the default site at port 80. I disabled this site using sudo a2dissite 000-default. Then reloaded apache. That solved the problem!

1 Like

If no ServerName is configured in that default vhost, it defaults to the hostname of the server, which often is the actual domain name which is being served. Thus you'd have two vhosts configured for the same thing.

3 Likes