I'm running Apache 2.4.52 on Ubuntu Server 22.04.
I'm trying to run https through port 443, eventually aiming to have a redirect from port 80 to force content on https. However, Apache seems to be using the DocumentRoot from the port 80 config, despite the browser connecting to the https url and being served the right SSL certificate.
For example:
<VirtualHost *:80>
ServerName [mydomain]
ServerAlias [www.mydomain]
DocumentRoot /var/www/testpage1/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
#Redirect permanent / https://[mydomain]
</VirtualHost>
<VirtualHost *:443>
ServerName [mydomain]
ServerAlias [www.mydomain]
DocumentRoot /var/www/testpage2/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/[mydomain]/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[mydomain]/privkey.pem
</VirtualHost>
results in the index.html from "/var/www/testpage1/" being shown instead of testpage2.
At this point, if I uncomment either
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
or
#RewriteEngine On
#Redirect permanent / https://[mydomain]
it just hits me with an "ERR_TOO_MANY_REDIRECTS"
If I comment out the DocumentRoot in the port 80 config, both the http and https url take me to the apache default config page.
And if I comment out the ServerName and ServerAlias in either the 80 or 443 config, both still take me to testpage1.
my ports.conf in /etc/apache2/ looks like this:
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
I've checked that the ssl module is turned on
In the Apache error logs, there is an AH01909 "server certificate does NOT include an ID which matches the server name" warning. Could this be an issue, or is there something else I'm missing?
Thanks for any help.