phpstudy配置https,開啟httpd-ssl.conf,Apache就啟動不了的原因
前幾天公司的網站需要升級https,網上有很多教程詳細描述了怎麼在phpstudy上面配置https,自己也是按照這些教程一步一步來的,但是複製檔案到httpd-ssl.conf,Apache就啟動不了,出現這個的原因肯定是複製的內容有錯誤,有錯誤的地方很大一部分就是在引用證書那一部分,一定要注意檢查,證書是否真正的被引入。
下方是我的httpd-ssl.conf檔案內容:
Listen 443
<VirtualHost *:443>
DocumentRoot "專案路徑" //這個專案路徑用的這個'\'斜槓
ServerName 域名
ServerAlias 域名
SSLEngine on
SSLProtocol TLSv1 TLSv1.1 TLSv1.2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "D:/phpStudy/PHPTutorial/Apache/conf/ssl/1p.crt" // 公鑰(檔名中有public),引用證書要用'/'這個斜槓
SSLCertificateKeyFile "D:/phpStudy/PHPTutorial/Apache/conf/ssl/2.key"// 私鑰, 引用證書要用'/'這個斜槓
SSLCertificateChainFile "D:/phpStudy/PHPTutorial/Apache/conf/ssl/3c.crt"//根證書(檔名有chain), 引用證書要用'/'這個斜槓
<Directory "專案路徑">
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
配置好httpd-ssl.conf,可以用phpstudy自帶的cmd命令列檢測下,是否能啟動
進入Apache\bin目錄輸入httpd.exe -t 檢查是否有錯。
最後在專案目錄建立一個無後綴的.htaccess檔案,以下是內容
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]