最近在搞https,筆記一些內容。
安裝憑證參考:
https://gcp.nat.gov.tw/views/AnnDownload/download_5.html
其中的 Apache TLS/SSL憑證請求檔製作與憑證安裝手冊
https://gca.nat.gov.tw/download/GCA_Apache_CSR_and_INSTALL.pdf
轉址參考:
https://www.opencli.com/apache/apache-http-to-https-redirect
1.下載申請完的憑證及轉換
a.到 https://gtlsca.nat.gov.tw/GCP/views/PEXE_Query/Query.CEXE
用憑證序號找到資料 按下載
b.下載下來的是一個xxxxx.cer (可以隨便改名字,只是要統一,範例為server2021.cer)
c.到openssl所在的資料夾 通常是apache/bin
用cmd執行下面這行
openssl x509 -in server2021.cer -inform DER -out server2021.crt
會得到一個叫 server2021.crt的檔案
2.至GTLSCA網站下載已經製作好的憑證串鏈檔案
下載網址為 https://gtlsca.nat.gov.tw/download/eCA1_GTLSCA.zip
將下載的eCA1_GTLSCA.zip解壓縮得到eCA1_GTLSCA.crt
3.修改httpd-ssl.conf
檔案通常在apache\conf\extra
找到下面三個參數
SSLCertificateFile:伺服器憑證(*.crt)檔案路徑(就是步驟1 轉換後的檔案)
SSLCertificateKeyFile:私密金鑰檔案路徑(這個是一開始申請時產生的.key檔 通常跟申請時的csr檔案一起)
SSLCertificateChainFile:eCA1_GTLSCA.crt 檔案路徑(步驟2 下載後解壓縮的東西)
修改範例(把三個檔案放在apache/conf/ssl2021 資料夾)
SSLCertificateFile "conf/ssl2021/server2021.crt"
SSLCertificateKeyFile "conf/ssl2021/server2021.key"
SSLCertificateChainFile "${SRVROOT}/conf/ssl2021/eCA1_GTLSCA.crt"
4.重啟apache 開啟port443防火牆
要注意httpd-ssl.conf中
a.有沒有Listen 443
b.VirtualHost 及 DocumentRoot 設定是否正確
5.自動從port80轉到443
可以用.htaccess,放在網站根目錄底下,在.htaccess中加上
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xxx.com/$1 [R,L]
其中 https://www.xxx.com/ 是你自己的網址
6.其他備註
申請時的需要的csr檔及SSLCertificateKeyFile,參考
https://docs.gandi.net/zh-hant/ssl/common_operations/csr.html
指令是
openssl req -nodes -newkey rsa:2048 -sha256 -keyout myserver.key -out server.csr
myserver.key是SSLCertificateKeyFile
server.csr是申請時的需要的csr檔
如果找不到openssl.cnf的話,先執行這一行
Set OPENSSL_CONF=(openssl.cnf所在路徑)\openssl.cnf
留言
張貼留言