<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shane Li on Medium]]></title>
        <description><![CDATA[Stories by Shane Li on Medium]]></description>
        <link>https://medium.com/@l83112006?source=rss-131fa96c4410------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*W3s8mmziztZe-u-XmA5Tsg@2x.jpeg</url>
            <title>Stories by Shane Li on Medium</title>
            <link>https://medium.com/@l83112006?source=rss-131fa96c4410------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:00:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@l83112006/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing Your Website End-to-End: A Detailed Guide to Automating SSL Certificate Renewal with acme.s]]></title>
            <link>https://medium.com/@l83112006/how-to-implement-auto-renew-https-to-website-bc0c68cc0e88?source=rss-131fa96c4410------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc0c68cc0e88</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[acme]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Shane Li]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 19:19:21 GMT</pubDate>
            <atom:updated>2024-04-02T19:42:06.682Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securing Your Website End-to-End: A Detailed Guide to Automating SSL Certificate Renewal with acme.sh and Nginx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gpF6DUrnyIn_EKLV" /><figcaption>Photo by <a href="https://unsplash.com/@ourselp?utm_source=medium&amp;utm_medium=referral">Philippe Oursel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>這篇文章旨在記錄如何使用 <a href="https://github.com/acmesh-official/acme.sh">acme.sh</a> 來安裝 SSL 憑證，實現網域的 HTTPS 加密保護。本文是基於我個人學習過程的分享，對於這一過程有任何見解或建議，我都非常歡迎大家的討論與交流。</p><p>若你正打算或已經在伺服器上部署網站專案，並尋求一個成本低廉且有效的方法來實現網站的基本 HTTPS 保護，那麼這篇文章將會是你的不二選擇。為了保證文章內容的專注性，我們將直接跳過網站部署的步驟，專注於網頁伺服器的配置過程。</p><p>在本文中，我將分享在 <strong>Ubuntu + Nginx + Docker Container</strong> 環境下，使用 acme.sh 實現自動更新 SSL 憑證的經驗。為了便於說明，我將使用示例網域 foobar.com 代替實際操作中的網域名稱。</p><p>首先，我們需要安裝 acme.sh。打開終端機（Terminal）並執行以下命令來進行安裝：</p><pre>curl https://get.acme.sh | sh -s email=admin@foobar.com</pre><p>安裝完畢後，輸入 acme.sh -v 確認安裝是否成功。你應該會看到類似以下的版本資訊：</p><pre>https://github.com/acmesh-official/acme.sh<br>v3.0.8</pre><p>確認 acme.sh 安裝無誤後，我們將使用它來驗證是否擁有網域的管理權。 acme.sh 提供了多種驗證方式，在此我選擇使用 DNS Record 進行驗證：</p><pre>acme.sh --issue --dns -d foobar.com --yes-I-know-dns-manual-mode-enough-go-ahead-please</pre><p>接著，你會收到一組用於 DNS TXT 記錄的值，將其添加到你的 DNS 記錄中。完成後，運行以下指令來續簽證書：</p><pre>acme.sh --renew -d foobar.com --yes-I-know-dns-manual-mode-enough-go-ahead-please</pre><p>值得注意的是，在此次命令中我們使用--renew而非--issue。當然也可以使用更簡單的預設 Nginx 方法來處理：</p><pre>acme.sh --issue --dns -d foobar.com --yes-I-know-dns-manual-mode-enough-go-ahead-please</pre><p>這個步驟完成後，你的畫面上應該會顯示出四個不同的 .cer 或 .key 檔案的存放位置。這些文件還不是我們最終需要的格式，因此我們需要將它們轉換為 Nginx 需要的 .pem 檔案。這可以透過 acme.sh 的憑證安裝功能來做到：</p><pre>acme.sh --install-cert -d fooabr.com \<br>--key-file       /etc/nginx/ssl/foobar.com/key.pem  \<br>--fullchain-file /etc/nginx/ssl/foobar.com/cert.pem \<br>--reloadcmd     &quot;service nginx force-reload&quot;</pre><p>在此命令中，我們指定了證書和私鑰文件的存放位置，並告訴 acme.sh 安裝完成後如何重啟 Nginx。隨後，我們可以修改 Nginx 的設定來強制所有 HTTP 連接跳轉至 HTTPS，確保網站的流量全面加密。</p><p>原本在預設的目錄 /etc/nginx/sites-enabled/ 下，我們可能已經有了類似以下的內容存在於 default.conf 中：</p><pre>server {<br>    listen 80;<br><br>    server_name _;<br><br>    location / {<br>        proxy_pass    http://localhost:1234;<br>    }<br>}</pre><p>表示我們的 Nginx 將 80 port 的 HTTP 連線 proxy 到本機端的 1234 port（Docker Container 對外暴露出來的 port），並且它允許任何 domain 作為連入的網址。</p><p>在這個基礎上，我們修改為以下內容：</p><pre>server {<br>        listen 80;<br><br>        server_name _;<br><br>        return 301 https://$host$request_uri;<br>}</pre><p>用意在自動將 80 port 的 HTTP 連線透過 301 轉址到使用 HTTPS 的原網址。並且新增 nginx.conf 來作為 server 的細節設定：</p><pre>server {<br>        listen 443 ssl;<br>        ssl_certificate         /etc/nginx/ssl/foobar.com/cert.pem;<br>        ssl_certificate_key     /etc/nginx/ssl/foobar.com/key.pem;<br><br>        server_name www.foobar.com;<br><br>        location / {<br>                proxy_pass      http://localhost:1234;<br>        }<br>}</pre><p>這裡我們將監聽的 port 設定為 443，並設定我們的網域要使用的 SSL 證書與金鑰路徑，這樣就可以將所有的網域流入流量透過剛剛已經安裝好的證書統一為 HTTPS。</p><p>透過 nginx -t 指令確認沒有問題的話，便可以透過 service nginx force-reload 使變更生效。</p><p>至此，我們已經完成了使用 acme.sh 自動更新 SSL 證書的整個過程。為了保證證書的持續有效，acme.sh 會自動處理證書的續期工作。你只需確認 cronjob 是否已正確設置即可。希望這篇文章能夠幫助到正尋找 HTTPS 實作方案的你。我們下次再見！</p><p>參考資料：<a href="https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E">https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc0c68cc0e88" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>