---
title: "Qnap Docker Station 建立 nginx-certbot 容器應用，幫您自動延展 letsencrypt 免費 https 憑證"
description: "說明如何在 QNAP NAS 的 Container Station 上建立 nginx-certbot 容器，自動每週檢查並延展 Let's Encrypt 免費 HTTPS 憑證。"
canonical_url: "https://blog.markkulab.net/post/nginx-certbot"
author: "Mark Ku"
author_url: "https://blog.markkulab.net/author/mark-ku"
site: "Mark Ku's Blog"
date_published: "2022-01-24 01:01:01 +0800"
category: "Infra"
tags: ["nginx", "certbot", "https", "letsencrypt", "docker", "qnap", "infra", "ssl"]
language: "zh-TW"
license: "CC BY 4.0"
license_url: "https://creativecommons.org/licenses/by/4.0/"
attribution: "轉載或引用請註明作者並附上原文連結"
---

# Qnap Docker Station 建立 nginx-certbot 容器應用，幫您自動延展 letsencrypt 免費 https 憑證

## 解決問題
[先前有透過 windows certbot](https://blog.markkulab.net/2021/12/26/ssl-certbot/) 申請免費的 https 憑證，但每三個月都要手動延展一次，很不方便，但透過  nginx-certbot 容器應用，可以自動延展 https 憑證。 

## 開發環境
* 採用 QNAP TS-253D 的 Container Station

## 安裝方式
### 1. 建立 > 搜尋 採用docker hub 上的 "staticfloat/nginx-certbot" 映像檔 > 安裝

![QNAP Container Station 搜尋 nginxcertbot 映像檔](https://blog.markkulab.net/content/markku/posts/nginx-certbot/images/t7W0TX1.png)

### 2. 依據以下面表格 掛載資料夾 ( Docker Volume )

| 掛載資料夾用途 | NAS 掛載資料夾位置 | 容器對映路徑 |
| -------- | -------- | -------- |
| nginx 設定檔路徑     | /share/Container/data/proxy-protocol   | /etc/nginx/conf.d      |
| letsencrypt log | /share/Container/data/proxy-protocol/log  | /var/log/letsencrypt |
| 己申請的 letsencrypt 舊憑證目錄     | Container/data/proxy-protocol/letsencrypt| /etc/letsencrypt   |
| nginx 網頁預設目錄  | /usr/share/nginx/html | Container/data/proxy-Container/data/proxy-protocol/web  |

![Qnap Container Station 建立容器的共用資料夾設定](https://blog.markkulab.net/content/markku/posts/nginx-certbot/images/z8q03u2.jpg)

### 3. 環境變數
CERTBOT_EMAIL => 當初申請 https 憑證的 email

![Qnap Container Station 設定 nginx-certbot 環境變數](https://blog.markkulab.net/content/markku/posts/nginx-certbot/images/sPLMPLG.png)

### 4. 將先前申請的憑證放置到指定位置
![Let's Encrypt 憑證檔案存放路徑截圖](https://blog.markkulab.net/content/markku/posts/nginx-certbot/images/ZMFyy5i.png)

### 5. 撰寫 nginx 設定檔，

```
upstream frp {
	server 34.80.106.95:80;  # 这个是frp_server的内网ip和http监听端口
}

server
	{
	
	listen 443 ssl http2 proxy_protocol;
	listen [::]:443 ssl http2;
	server_name www.letgo.com.tw; # local server ip

	set_real_ip_from 172.31.0.1; # frp client ip
	real_ip_recursive on;
	real_ip_header  proxy_protocol;


	    ssl_certificate     /etc/letsencrypt/live/www.letgo.com.tw/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.letgo.com.tw/privkey.pem;
	
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

	ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
	ssl_prefer_server_ciphers on;
	ssl_session_cache shared:SSL:10m;
	ssl_session_timeout 10m;
	add_header Strict-Transport-Security "max-age=31536000";	

	location / {
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_protocol_addr;		
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_pass http://192.168.50.52:8890/; # your local application ip
	}
}
```
![Qnap檔案總管顯示proxy-protocol資料夾內容](https://blog.markkulab.net/content/markku/posts/nginx-certbot/images/7eMOn4S.png)

### 6. 啟動容器應用，則會每週檢查，並自動幫你延展免費的 https 憑證。

## 備註
* letsencrypt 資料夾不能亂刪，否則下次更新會失敗。
* 我的網路架構有用 frp，frp 不能區分 http 及 https ，會自動昇級 https，因此第一次 http 挑戰，我是移到 IIS 驗證。

---

## 關於本文與作者

本文出自 [Mark Ku's Blog](https://blog.markkulab.net/post/nginx-certbot)

授權條款： [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) — 轉載或引用請註明作者並附上原文連結

### 關於作者

**[Mark Ku](https://blog.markkulab.net/author/mark-ku)** — Software Solution Provider

- 10+ 年資深軟體工程師，現為 AI 應用 Builder
- 專注大型平台架構設計，從北美電商到AI SaaS訂閱收費系統
- 結合 AI Agent 與自動化，打造高效可演進的產品技術基礎

### 作者開發的免費工具

以下工具皆可免費使用：

- [免費 PDF 簽名工具](https://blog.markkulab.net/tools/pdf-sign): 線上 PDF 簽名工具，瀏覽器內完成手繪、打字、上傳簽名，可拖曳放置、縮放、下載。所有處理都在你的裝置完成，檔案不會上傳。
- [VS Code Refactory](https://blog.markkulab.net/tools/refactory): Refactory 是一款 VS Code 重構擴充套件：34 個重構動作、37 條 code smell 檢查、Code Health 儀表板、18 種語言、534 支測試。懂你的專案慣例：介面放哪、DI 註冊寫在哪、'use client' 該不該加；還會用 git 修改頻率 × 複雜度排出「該先修哪個檔案」，並一鍵把壞味道交給你自己電腦上的 Claude Code 修。免費使用，原始碼不離開你的機器。
- [DB-Kit 資料庫管理工具](https://blog.markkulab.net/tools/db-kit): DB-Kit 是一個用 Tauri + Rust + React 打造的輕量跨平台資料庫管理工具，用單一一致的介面同時管理 MySQL、MariaDB、PostgreSQL、SQL Server、Oracle、SQLite、MongoDB、Redis、Kafka、Elasticsearch 與 RabbitMQ 十一種資料來源：連線密碼以 OS keychain 加密、SSH Tunnel、完整 CRUD、視覺化查詢建構器、多結果集同時顯示、跨連線資料傳輸與比對同步、Excel / CSV 匯入匯出、執行計畫視覺化、ER 圖、排程備份、SQL 壓力測試（p50～p99 延遲百分位）、15 條規則的 SQL 審查、Kafka 訊息瀏覽與監控告警；繁中 / 英文雙語介面，內建 AI 助手（自然語言生成 SQL、AI 審查與調校建議）與命令列工具 dbk。免費開源（MIT），提供 Windows / macOS / Linux 安裝檔。
- [VS Code Super Mermaid](https://blog.markkulab.net/tools/super-mermaid): Super Mermaid 是一款 VS Code 擴充套件：開箱即用的漂亮 Mermaid 圖表，自動上色、即時預覽、滑鼠平移縮放、PNG / SVG 高解析匯出，內建 21 種範本與多種主題。免費開源（MIT）。
- [React Super Mermaid](https://blog.markkulab.net/tools/react-super-mermaid): react-super-mermaid 是一個開源 React 元件庫：一行 <MermaidViewer> 即可渲染漂亮的 Mermaid 圖表，內建 colorful / sketch 主題、平移縮放、圖內搜尋、SVG / PNG 高解析匯出。輕量、SSR 安全、完整 TypeScript 型別。免費開源（MIT）。
- [Jira / Confluence Super Mermaid](https://blog.markkulab.net/tools/jira-super-mermaid): Atlassian Forge app：在 Jira issue 與 Confluence 內文直接寫 Mermaid 語法，畫流程圖、時序圖、狀態機與甘特圖。11 種圖表、SVG / PNG 匯出、明暗主題、完整中日韓文字支援。取得 Runs on Atlassian 資格：圖表存在你自己的站台，app 不呼叫任何第三方服務。免費，即將上架 Atlassian Marketplace。
- [Mermaid 線上預覽](https://blog.markkulab.net/tools/mermaid-preview): 在瀏覽器裡寫 Mermaid、即時看圖，整張圖表壓進網址就能分享。免註冊、不上傳伺服器，相容 mermaid.live 的分享連結。
- [React Intl Phone Number](https://blog.markkulab.net/tools/react-intl-phone-number): react-intl-phone-number 是一個開源 React 元件：framework-agnostic、不依賴 antd，提供 E.164 進出、可搜尋國旗 / 國碼下拉、可配置驗證等級（strict / mobile-strict / loose）、可主題化 CSS 與 i18n，電話邏輯由 google-libphonenumber 驅動。輕量、完整 TypeScript 型別。免費開源（MIT）。
- [Uptime Kuma Cluster](https://blog.markkulab.net/tools/uptime-kuma-cluster): 把單機版 Uptime Kuma 改造成高可用叢集：OpenResty + Lua 智慧負載平衡、MariaDB 共享狀態、健康檢查與自動 Failover，附叢集管理 REST API，一行 Docker Compose 啟動。免費開源（MIT）。
- [特教專案](https://blog.markkulab.net/education): 為特殊教育學生製作的學習教材

### 每日 Podcast

- [科技新鮮事](https://blog.markkulab.net/category/tech-news): 每日精選 AI 與科技趨勢，透過語音摘要快速掌握最新技術動態，涵蓋 AI 應用、軟體架構、DevOps 與工程實戰。 — RSS: https://blog.markkulab.net/feed.xml
- [AI股市蝦聊](https://blog.markkulab.net/category/ai-stock-chat): 每個交易日用 AI 分析台股盤勢，以雙人對話聊當天的盤中觀察與隔日預測。 — RSS: https://blog.markkulab.net/ai-stock-chat/feed.xml

### 電子報

[訂閱電子報](https://blog.markkulab.net/subscribe) — 第一時間收到新文章通知，無垃圾信、隨時可取消訂閱。
