http에서 https로 리디렉션할 수 없습니다.

http에서 https로 리디렉션할 수 없습니다.

이 질문에 대해 100번 이상 답변을 받았을 것이라고 확신합니다(거의 모두 읽었기 때문입니다). 그러나 Apache2 리디렉션이 작동하도록 할 수는 없습니다.

나는 리눅스의 모든 것에 관한 완전 초보자이고 현재 웹사이트를 실행하려고 노력하고 있습니다. 사이트는 이미 https에서 사용할 수 있으며 인증서가 있습니다.

포트 80에 대한 잘못된 요청

/etc/apache2/ports.conf

Listen 80
<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

etc/apache2/sites-available/mydomainname.conf

NameVirtualHost *:80
NameVirtualHost <mydomainname>:443
<VirtualHost *:80>
        ServerName <mydomainname>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTPS_HOST}%{REQUEST_URI} [R,L]

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

<VirtualHost _default_:443>
        ServerName <mydomainname>
        DocumentRoot /var/www/html
        SSLEngine On
</VirtualHost>

sudo a2ensite <mydomainname>.conf이것이 중요하다면 나는 이미 실행했습니다 .

답변1

:443 에 몇 가지 중요한 지시어가 누락되었습니다 VirtualHost. SSL 인증서 파일과 개인 키가 지정되지 않았습니다.

지시문은 VirtualHost다음과 같아야 합니다.

Listen 443
<VirtualHost *:443>
    ServerName example.com
    SSLEngine on
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"
</VirtualHost>

공식을 확인하세요아파치 문서상세 사항은:

관련 정보