Mark Ku's Blog

解決問題

先前有透過 windows certbot 申請免費的 https 憑證,但每三個月都要手動延展一次,很不方便,但透過 nginx-certbot 容器應用,可以自動延展 https 憑證。

開發環境

  • 採用 QNAP TS-253D 的 Container Station

安裝方式

1. 建立 > 搜尋 採用docker hub 上的 "staticfloat/nginx-certbot" 映像檔 > 安裝

QNAP Container Station 搜尋 nginxcertbot 映像檔
QNAP Container Station 搜尋 nginxcertbot 映像檔

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/htmlContainer/data/proxy-Container/data/proxy-protocol/web
Qnap Container Station 建立容器的共用資料夾設定
Qnap Container Station 建立容器的共用資料夾設定

3. 環境變數

CERTBOT_EMAIL => 當初申請 https 憑證的 email

Qnap Container Station 設定 nginx-certbot 環境變數
Qnap Container Station 設定 nginx-certbot 環境變數

4. 將先前申請的憑證放置到指定位置

Let's Encrypt 憑證檔案存放路徑截圖
Let's Encrypt 憑證檔案存放路徑截圖

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資料夾內容
Qnap檔案總管顯示proxy-protocol資料夾內容

6. 啟動容器應用,則會每週檢查,並自動幫你延展免費的 https 憑證。

備註

  • letsencrypt 資料夾不能亂刪,否則下次更新會失敗。
  • 我的網路架構有用 frp,frp 不能區分 http 及 https ,會自動昇級 https,因此第一次 http 挑戰,我是移到 IIS 驗證。

作者

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。閱讀更多

覺得這篇有幫助?

作者做的免費工具、每日 Podcast 與電子報,都在這裡。

Mark Ku · 本文採用 CC BY 4.0 授權,轉載請註明作者並附上原文連結。

留言

訂閱電子報

訂閱後即時收到新文章通知,不錯過任何技術分享。

提交即表示同意接收電子報,隨時可

熱門文章

View all
Mark Ku
··603

Oracle Cloud 永久免費方案 Linux 主機及固定 IP :0 元打造雲端解決方案

Oracle Cloud 永久免費方案 Linux 主機及固定 IP :0 元打造雲端解決方案
Mark Ku
··440

告別 Postman 收費陷阱!開源 Git 原生 API 測試神器 Bruno 實戰指南

告別 Postman 收費陷阱!開源 Git 原生 API 測試神器 Bruno 實戰指南
Mark Ku
··323

一款免費開源類似於 Notion 類知識庫系統 — Outline Wiki 佈署與備份全攻略

一款免費開源類似於 Notion 類知識庫系統 — Outline Wiki 佈署與備份全攻略
Mark Ku
··239

打造高效 API 管理平台:從 0 開始部署 Kong Gateway - Part 1

打造高效 API 管理平台:從 0 開始部署 Kong Gateway - Part 1
Mark Ku
··222

在 Ubuntu 上設置 Samba 來共享資料夾,讓 Windows 11 用戶可以存取

在 Ubuntu 上設置 Samba 來共享資料夾,讓 Windows 11 用戶可以存取
Mark Ku
··199

訓練自己的 AI 語音:硬體門檻、開源模型比較與 LoRA 微調

訓練自己的 AI 語音:硬體門檻、開源模型比較與 LoRA 微調