동일한 서버에 있는 두 웹사이트의 잘못된 https 리디렉션

동일한 서버에 있는 두 웹사이트의 잘못된 https 리디렉션

웹사이트가 2개 있습니다. 전화해 보세요.example-1.com그리고example-2.com동일한 서버에 배포됨(센트OS 7.5) 둘 다 포트 80에서 Apache에 의해 제공됩니다. 리디렉션은 가상 호스트를 통해 수행됩니다(전체 구성은 아래 참조).

두 사이트 모두에서 (영구적으로) 리디렉션합니다.http는 https로의 URL입니다(인증서에는 문제가 없으며 봇은 잘 작동합니다).

내가 직면한 문제는 두 번째 웹 사이트의 http 버전이 첫 번째 웹 사이트의 https로 리디렉션(영구 이동, 301)된다는 것입니다(사이트의 순서는 아래 .conf 파일에 따릅니다).

이 리디렉션은 두 번째 웹 사이트가 첫 번째 웹 사이트로 리디렉션되는 경우 발생하지 않습니다(아래 conf 참조). 또한 http에서 https로 리디렉션할 필요가 없는 경우 모든 것이 정상적으로 작동합니다. 즉, 다음으로 시작합니다.https://www.example-2.com.

다음은.conf파일, 이 문제를 해결하는 방법에 대한 아이디어를 주시면 감사하겠습니다.

Listen 80

<VirtualHost *:80>
    ServerName example-1.com
    Redirect permanent / https://www.example-1.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/html/example-1"
    ServerName www.example-1.com
    ServerAlias example-1.com

## logging
   ErrorLog "/var/log/httpd/example-1-error_log"
   CustomLog "/var/log/httpd/example-1-access_log" combined

        <Directory "/var/www/html/example-1">
                DirectoryIndex index.html index.php
                Options FollowSymLinks
                AllowOverride All
       </Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example-1.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example-1.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example-1.com/chain.pem
</VirtualHost>
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
</IfModule>

그리고conf두 번째 웹사이트(이름을 제외한 유일한 차이점은 두 번째 웹사이트에는들어봐 80상단에)

<VirtualHost *:80>
    ServerName example-2.com
    Redirect permanent / https://www.example-2.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/html/example-2"
    ServerName www.example-2.com
    ServerAlias example-2.com

## logging
   ErrorLog "/var/log/httpd/example-2-home-error_log"
   CustomLog "/var/log/httpd/example-2-home-access_log" combined

        <Directory "/var/www/html/example-2">
                DirectoryIndex index.html index.php
                Options FollowSymLinks
                AllowOverride All
        </Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example-2.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example-2.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example-2.com/chain.pem
</VirtualHost>
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
</IfModule>

답변1

마침내 내 구성에서 무엇이 잘못되었는지 찾아낸 것 같습니다. 누군가 비슷한 문제를 겪을 경우를 대비해 여기에 게시합니다.

서버 이름을 www에 해당하는 이름으로 변경하고 www가 없는 서버 별칭을 추가했습니다. 즉, 이제 지시어는 다음과 같습니다.

<VirtualHost *:80>
    ServerName www.example-1.com
    ServerAlias example-1.com
    Redirect permanent / https://www.example-1.com/
</VirtualHost>

두 번째 웹사이트에도 동일한 조정이 적용됩니다. 이로 인해 잘못된 리디렉션 문제가 해결되었습니다.

관련 정보