Apache-2.4
Apache 不會強制 https://domain 到 https://www.domain(重寫不起作用)
設置 Apache 2.4 和 Wordpress 後,我收到以下 SSL 錯誤消息:
$ wget "https://example.com" Resolving example.com (example.com)... 192.168.15.5 Connecting to example.com (example.com)|192.168.15.5|:443... connected. ERROR: no certificate subject alternative name matches requested host name ‘ example.com’. To connect to example.com insecurely, use `--no-check-certificate'.
為了使域名與我的 SSL 證書 (
www.example.com
) 匹配,我嘗試調整站點配置以將https://example.com>重定向到<https://www.example.com。但它不起作用:http-to-https 重定向功能如預期,但裸域到 www-domain 沒有。這是我的站點配置:
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com Redirect permanent / https://www.example.com/ </VirtualHost> <IfModule mod_ssl.c> <VirtualHost _default_:443> ServerName www.example.com Protocols h2 http/1.1 ServerAdmin webmaster@localhost DocumentRoot /var/www/html DirectoryIndex index.php RewriteEngine on #### Doesn’t work at all #### RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^/(.*) https://www.example.com/$1 [L,R=301] ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # SSL with Letsencrypt Include /etc/letsencrypt/options-ssl-apache.conf SSLEngine on SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem </VirtualHost> </IfModule>
該站點本身執行良好,並且
.htaccess
僅包含由 Wordpress 創建的行。任何輸入表示讚賞。
您仍然需要有效的證書
http://example.com
。重定向發生在建立有效的 TLS 連接之後。在 SAN 欄位中
example.com
獲取證書。www.example.com