it-swarm.com.de

Phantom-VHOST-Weiterleitung von example.com an example.net

Ich führe Apache2 unter Ubuntu 16.04 LTS aus und verschlüssele Certbot für SSL-Zertifikate.

Ich habe zwei Domänen. Unabhängig davon, ob http oder https, www oder non-www, ich möchte, dass sie bei https://example.com bzw. https://example.net landen.

Ich habe 4 .conf-Dateien pro Domain: HTTP WWW, HTTP NON-WWW, HTTPS WWW, HTTPS NON-WWW. HTTPS NON-WWW sollte immer das Endergebnis sein.

Site 01: example.com

http://example.com -forwards to- https://example.com [OK]
http://www.example.com -forwards to- https://example.com [OK]
https://www.example.com -forwards to- https://example.com [OK]
https://example.com works as expected [OK]

Site 02: example.net

http://example.net -forwards to- https://example.net [OK]
http://www.example.net -forwards to- https://example.com [ERROR]
https://www.example.net -forwards to- https://example.net [OK]
https://example.net works as expected [OK]

Ich möchte, dass http://www.example.net an https://example.net weiterleitet, nicht an https://example.com

Meine .conf-Dateien:

##Site 01: example.com - HTTP NON-WWW .conf##
    <Directory /var/www/html/example.com/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/html/example.com/public_html

        ErrorLog /var/www/html/example.com/logs/error.log
        CustomLog /var/www/html/example.com/logs/access.log combined

        RedirectMatch permanent ^/(.*) https://example.com/$1
    </VirtualHost>

##Site 01: example.com - HTTPS WWW .conf##
    <IfModule mod_ssl.c>
    <Directory /var/www/html/example.com/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:443>
        ServerName www.example.com
        DocumentRoot /var/www/html/example.com/public_html

        ErrorLog /var/www/html/example.com/logs/error.log
        CustomLog /var/www/html/example.com/logs/access.log combined

        RedirectMatch permanent ^/(.*) https://example.com/$1

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

##Site 01: example.com - HTTPS NON-WWW .conf##
    <IfModule mod_ssl.c>
    <Directory /var/www/html/example.com/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:443>
        ServerName example.com
        DocumentRoot /var/www/html/example.com/public_html

        ErrorLog /var/www/html/example.com/logs/error.log
        CustomLog /var/www/html/example.com/logs/access.log combined

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

##Site 02: example.net - HTTP WWW .conf##
    <Directory /var/www/html/example.net/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:80>
        ServerName www.example.net
        DocumentRoot /var/www/html/example.net/public_html

        ErrorLog /var/www/html/example.net/logs/error.log
        CustomLog /var/www/html/example.net/logs/access.log combined

        RedirectMatch permanent ^/(.*) https://example.net/$1
    </VirtualHost>

##Site 02: example.net - HTTP NON-WWW .conf##
    <Directory /var/www/html/example.net/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/html/example.net/public_html

        ErrorLog /var/www/html/example.net/logs/error.log
        CustomLog /var/www/html/example.net/logs/access.log combined

        RedirectMatch permanent ^/(.*) https://example.net/$1
    </VirtualHost>

##Site 02: example.net - HTTPS WWW .conf##
    <IfModule mod_ssl.c>
    <Directory /var/www/html/example.com/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:443>
        ServerName www.example.com
        DocumentRoot /var/www/html/example.net/public_html

        ErrorLog /var/www/html/example.net/logs/error.log
        CustomLog /var/www/html/example.net/logs/access.log combined

        RedirectMatch permanent ^/(.*) https://example.net/$1

        SSLCertificateFile /etc/letsencrypt/live/example.net/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.net/privkey.pem
        Include /etc/letsencrypt/options-ssl-Apache.conf
    </VirtualHost>
    </IfModule>

##Site 02: example.net - HTTPS NON-WWW .conf##
    <IfModule mod_ssl.c>
    <Directory /var/www/html/example.com/public_html>
        Require all granted
    </Directory>

    <VirtualHost *:443>
        ServerName example.net
        DocumentRoot /var/www/html/example.net/public_html

        ErrorLog /var/www/html/example.net/logs/error.log
        CustomLog /var/www/html/example.net/logs/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/example.net/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.net/privkey.pem
        Include /etc/letsencrypt/options-ssl-Apache.conf
    </VirtualHost>
    </IfModule>
3
iverSUN

Sie haben einfach einen Tippfehler in einem Ihrer virtuellen Hosts:

    ServerName www.example.com
    DocumentRoot /var/www/html/example.net/public_html
    ...
    RedirectMatch permanent ^/(.*) https://example.net/$1

Das ServerName ist falsch. Sie haben wegen des Tippfehlers überhaupt keinen virtuellen Host für www.example.net eingerichtet. Das bedeutet, dass www.example.net auf den voreingestellten (ersten) virtuellen Host zurückgreift. Deshalb wird es an die falsche Stelle weitergeleitet.

1