http から https にリダイレクトできません

http から https にリダイレクトできません

この質問には 100 回以上回答されているはずです (ほぼすべて読んだので) が、Apache2 のリダイレクトが機能しません。

私は Linux に関するあらゆることに関して完全な初心者で、現在 Web サイトを運営しようとしています。サイトはすでに https で利用可能であり、証明書も持っています。

ポート 80 の不正なリクエスト

ポート

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>

公式をチェックApache ドキュメント詳細については:

関連情報