看臉書上說, 現在大部分的網站都用 HTTPS 了. 雖然說臉書假新聞多, 那我這個站呢? 我把我改 HTTPS 的心得跟大家也分享一下.
首先, XAMPP 就可以自行產生 key, 變成 HTTPS 的網站 [1]. Keyword 就是 makecert.bat 打下去就對了! 在交互式的輸入中, 除了 Common Name 要打 IP 或是 domain name 之外, 沒有什麼難的. 做完之後, 它自動會把三把 key 放到 apache/conf/ 下面的三個目錄:
ssl.csr 裡面放 server.csr
ssl.crt 裡面放 server.crt
ssl.key 裡面放 server.key
這樣第一階段就完成了. 第二步要確定 apache/conf/ 下的 httpd.conf 裡面,
LoadModule rewrite_module modules/mod_rewrite.so
這行的註解 (‘#’) 被拿掉後, 用 https://www.cash.idv.tw 就可以連上我的網站了. 當然, 後面還有一些細節是要保護那些目錄? 這個我先略過不提. 我要講的重點是, 如果用 chrome browser 去連 https://www.cash.idv.tw, 它竟然把我的 https 用斜線劃掉了, 這樣看起來好丟臉啊!
查了前人的文章 [2], 才知道 Chrome 會檢查憑證是否為第三方所認證的. 我們自己產生出來的 key, 當然不能說很有說服力, 有人證認確實比較好. 怎麼辦呢? 找到一個 SSL for free 可以解決這個問題 [3], 只要按照網站上說的, 產生 SSL key 應該不困難.
在這個過程中, 我發現我在 PCHOME 代管的 DNS, 只有註冊 http://www.cash.div.tw, 沒註冊 cash.idv.tw. 把這個問題修正了之後, 才能夠通過 SSL fro free 的測試. 如果一切順利, SSL for free 網站會生出三個檔案, 打包成一個 sslforfree.zip 下載.
這個 zip 檔解開之後, 會看到 ca_bundle.crt, certificate.crt, private.key 三個檔案. 看起來只要能用這三個檔案代替 XAMPP 的三個檔案, 那麼 Chrome browser 也不能再挑剔我的 key 沒有公信力了吧!
話雖如此. 那個對到哪個呢? 這訊息我 Google 不到, 畢竟用 SSL for free 的人和用 XAMPP 的人交集很少吧!? 那就只好自己來了. 雖然我好想靠別人哪~~~
根據 /apache/conf/extra/httpd-ssl.conf 裡面寫的, private.key 顯然就是 server.key
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you’ve both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
# ECC keys, when in use, can also be configured in parallel
SSLCertificateKeyFile “conf/ssl.key/server.key"
CA 是第三方認證的. 顯然是 ca_bundle.crt 那包, 要放到 ssl.crt, 我把 ca_bundle.crt 直接 rename 成 ssl.crt 下的 server.crt. 不 rename 改 config 檔也可以通.
# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
# Note: Inside SSLCACertificatePath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCACertificatePath “c:/Apache24/conf/ssl.crt/"
#SSLCACertificateFile “c:/Apache24/conf/ssl.crt/ca-bundle.crt"
最後是 certificate.crt, 難不成它就是 ssl.csr 下的 server.csr? 看起來也的確有對上.
# Server Certificate:
# Point SSLCertificateFile “conf/ssl.crt/server.crt"
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. Keep
# in mind that if you have both an RSA and a DSA certificate you
# can configure both in parallel (to also allow the use of DSA
# ciphers, etc.)
# Some ECC cipher suites (http://www.ietf.org/rfc/rfc4492.txt)
# require an ECC certificate which can also be configured in
# parallel.
SSLCertificateFile “conf/ssl.crt/server.crt"
把這三個檔案各自 rename 之後, Chrome 也就不抱怨我的 https 了. 測試了一下 http 和 https 都可以連上我的網站. 按照網路上的說法, 應該要把 http 的網址關掉, 然後只用 https 的網址. 或者把 http 的 request 都 redirect 到 https. 不過, 只要我打開 SSLRequireSSL, XAMPP 就開不起來了. 這個我還在研究中. 總之, 我把 Chrome 的紅字先劃掉了!
SSL for Free | apache 目錄 | 重新命名 |
ca_bundle.crt | ssl.crt | server.crt |
certificate.crt | ssl.csr | server.csr |
private.key | ssl.key | server.key |
2017/2/26 補充
如果要在後台強制使用 https, 參考 [4] 這篇, 在 wp-config.php 當中, 在 下面這段出現之前 (它通常在最後一行).
/** 設定 WordPress 變數和包含的檔案。 */
require_once(ABSPATH . ‘wp-settings.php’);
加入下面的 define. 因為有版本新舊的關係. 可以兩個都加.
define(‘FORCE_SSL_ADMIN’, true); /* 新版適用 */
define(‘FORCE_SSL_LOGIN’, true); /* WordPress version 4 以後就不用了 */
[REF]