透過 WIN-ACME 申請並自動更新 Windows Apache 上的 Let’s Encrypt 憑證

  先前有寫過一篇「在 Windows 申請 Let’s Encrypt wildcard 憑證」,該篇主要是透過 “Get HTTPS for free!” 網站以動手動方式申請或展延憑證。最近在架新的網站時,試著用 WIN-ACME 工具來申請,以方便之後使用其自動展延 (renewal) 功能。

 

◎ 首先至 WIN-ACME 的 GitHub 下載最新的工具這邊以 win-acme.v2.1.22.1260.x64.pluggable.zip 為範例

◎ 下載完成並解壓縮後以「系統管理員身分」執行 wacs.exe

◎ 接下來主要都是以 WIN-ACME 官方針對 apache 環境的範例設定。

 

◎ 輸入 “m”,手動設定各參數

 

◎ 輸入 “m或按 Enter (預設 m),手動設定各參數

 

◎ 輸入要申請憑證的網址如 www.abc.com

 

◎ 為此域名輸入一個好識別的別名,Or press Enter to use the default value。

 

◎ 輸入 “1”,Provide the local website directory path for domain validation。

 

◎ Enter the local website root directory path,For example C:\Web\Apache24\htdocs\abc

 

◎ 輸入 “yes”,Allow the program to copy web.config to the website directory for validation。

 

◎ 輸入 “2” 或按 Enter (Default 2),Generate private key with RSA。

 

◎ 輸入 “2”,Generate a PEM certificate file suitable for Apache。

 

◎ Enter the directory path where you want to save the certificate file,For example C:\Web\SSL

 

◎ 輸入 “2”,Add a password to the private key,or enter “1” Do not encrypt。

 

◎ If you do not need to generate a second certificate,輸入 “5” 或按 Enter (Default 5) 繼續。

 

◎ If there are no special requirements,輸入 “3” 或按 Enter (Default 3) 繼續。

 

◎ After verification passes,a schedule to check certificate updates will be added in 'Task Scheduler',If this task does not need to be run under a specific identity,輸入 “no” 繼續。

 

◎ At this point,the certificate application is complete。

 

◎ Next, you can check the newly generated certificate in the certificate directory。

註. *-crt.pem + *-chain-only.pem = *-chain.pem

 

◎ 在「工作排程器」可以看到新增了一個 WIN-ACME 的項目

 

◎ 開啟 apache 的 httpd-ahssl.conf (或 httpd-ssl.conf 或 httpd.conf看你的環境),增加一組 SSL 的 VirtualHost

<VirtualHost *:443>
  SSLEngine on
  ServerName www.abc.com:443
  SSLCertificateFile "C:\Web\SSL\www.abc.com-chain.pem"
  SSLCertificateKeyFile "C:\Web\SSL\www.abc.com-key.pem"
  DocumentRoot "${SRVROOT}/htdocs/abc"
</virtualhost>

 

◎ 如果 80 port 的 VirtualHost 不關但想將 80 自動轉至 443,可在 80 port 的 VirtualHost 增加Redirect參數

<VirtualHost *>
 DocumentRoot C:\Web\Apache24\htdocs\abc
 ServerName www.abc.com
 Redirect / https://www.abc.com/
</VirtualHost>

註. https://www.abc.com/ 後面要有斜線這樣才會將 http://www.abc.com/def 導至 https://www.abc.com/def否則會變成 http://www.abc.comdef

 

[Related Links]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.