Apache2 serves wrong certificate

Overall looks great. Much cleaner and easier to maintain

Some of your redirects from HTTP to HTTPS are not working for clanmills VHost. Only clanmills.co.uk redirects properly. Familytree VHost is okay.

Following the same rewrite style in familytree :

Modify the Rewrites here
/etc/apache2/sites-enabled/clanmills.co.uk.conf

To look like

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =clanmills.com [OR]
    RewriteCond %{SERVER_NAME} =www.clanmills.com [OR]
    RewriteCond %{SERVER_NAME} =clanmills.co.uk [OR]
    RewriteCond %{SERVER_NAME} =www.clanmills.co.uk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
2 Likes

Right. I've changed /etc/apache2/sites-enabled/clanmills.co.uk.conf Thanks very much.

<VirtualHost *:80>
	# Servernames:
    ServerName  clanmills.co.uk
    ServerAlias clanmills.com
    ServerAlias www.clanmills.co.uk
    ServerAlias www.clanmills.com
    
    # Directories and files:
    DocumentRoot /home/._default_hostname/public_html
    ErrorLog     /var/log/virtualmin/clanmills.co.uk_error_log
    CustomLog    /var/log/virtualmin/clanmills.co.uk_access_log combined
    ScriptAlias  /cgi-bin/     /home/._default_hostname/cgi-bin/
    DirectoryIndex index.php index.htm index.html
    <Directory /home/._default_hostname/public_html>
        Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch 
        Require all granted
        AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        AddType text/plain .php
    </Directory>
    <Directory /home/._default_hostname/cgi-bin>
        Require all granted
        AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    </Directory>

    # rewrite engine
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =clanmills.com [OR]
    RewriteCond %{SERVER_NAME} =www.clanmills.com [OR]
    RewriteCond %{SERVER_NAME} =clanmills.co.uk [OR]
    RewriteCond %{SERVER_NAME} =www.clanmills.co.uk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    
</VirtualHost>

familytree serves the correct file:

root@clanmills:/etc/apache2/sites-available# cat /var/www/familytree/foo.txt
i am foo.txt
root@clanmills:/etc/apache2/sites-available# 

From my macOS desktop:

576 rmills@rmillsm4:~ $ curl --verbose https://familytree.clanmills.com/foo.txt
* Host familytree.clanmills.com:443 was resolved.
* IPv6: (none)
* IPv4: 147.93.86.33
*   Trying 147.93.86.33:443...
* Connected to familytree.clanmills.com (147.93.86.33) port 443
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=familytree.clanmills.com
*  start date: Oct  5 13:28:57 2025 GMT
*  expire date: Jan  3 13:28:56 2026 GMT
*  subjectAltName: host "familytree.clanmills.com" matched cert's "familytree.clanmills.com"
*  issuer: C=US; O=Let's Encrypt; CN=E8
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://familytree.clanmills.com/foo.txt
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: familytree.clanmills.com]
* [HTTP/2] [1] [:path: /foo.txt]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [accept: */*]
> GET /foo.txt HTTP/2
> Host: familytree.clanmills.com
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/2 200 
< last-modified: Thu, 09 Oct 2025 16:53:04 GMT
< etag: "d-640bca27bd08d"
< accept-ranges: bytes
< content-length: 13
< content-type: text/plain
< date: Thu, 09 Oct 2025 16:57:56 GMT
< server: Apache
< 
i am foo.txt
* Connection #0 to host familytree.clanmills.com left intact
577 rmills@rmillsm4:~ $ 

This is wonderful. For sure, this is clean and straightforward and much better than Sunday's 'pigsty'. Thank you again.

1 Like