極速打造 https://localhost

Ian Wu
Ian Wu
Sep 8, 2018 · 3 min read

在 locahost 測試 Facebook Login 的功能需要使用 https 連線,本來想用 ngrok 不過看了一下,要自訂 domain 可要不少錢。

於是找了一下讓 localhost 有 SSL 的方法,發現蠻簡單就弄好,以下就是極速生成法

產生憑證

用這行 code 就會生成 localhost.keylocalhost.crt

openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

憑證加入 trust store

鑰匙圈存取 > 檔案 > 輸入項目,選剛剛產生的 localhost.crt

信任憑證

選擇剛剛匯入的憑證 > 取得資訊

通通改成「永遠信任」

啟動 Server

登愣!完成

如果喜歡我的文章,歡迎點上面的 LIKE 喔

備註

  • Chrome 會 cache 憑證,如果還是顯示不安全,可以多重整幾次

相關文章

參考資料

Ian Wu

Written by

Ian Wu

住在台北的生活觀察家

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade