Birth: 2025-10-08 09:33:00
Modify:
Overview
[toc]
以下說明如何在啟用 Cloudflare Proxy 的情況下,配置 Cloudflare SSL Certs (End-to-End Encryption)。
Cloudflare DNS/Proxy
首先,你需要在 Cloudflare DNS 中新增至少一筆 A Record,並啟用 Proxy。
- Name: 看你的需求。 (通常是
example.com(無子網域),或是www,api之類的) - IPv4 address: Host的public IP。
Create SSL/TLS Certs
Full (Strict)
- 去 SSL/TLS Overview,將 Encryption Mode 設定為 Full (Strict)
Create Origin Certificates
- 去 SSL/TLS Origin Server,建立Origin Certificates
-
Hostnames: 指定cert可用的domain
- 無子網域:
example.com - 子網域:
api.example.com - wildcard:
*.example.comexample.com
再來會看到Cert and Key,先找地方存起來,然後確認。
- 無子網域:
Backend Setup
你現在要把income的443 traffic使用前面的Cert and Key解成http。
Backend example: Nginx
在你的server block內,你要listen 443 ssl;,然後指定好你前面保存的Cert and Key。
server {
# 這邊重要
listen 443 ssl;
# 這邊重要
ssl_certificate /path/to/your/cert.pem;
ssl_certificate_key /path/to/your/key.pem;
# server_name: 用來指定此伺服器能處理的網域。
# ex.
# 網站: example.com -> server_name example.com;
# 網站: api.example.com -> server_name api.example.com;
# 要使用 server_name _; wirecard 也行
server_name example.com;
# 底下是其他設定,可能proxy_pass去http server。
location / {
proxy_pass http://your_backend;
# ...
}
# ...
結果
完成上述設定後,client 以 domain 存取網站時,連線將會使用 HTTPS , 並且End-to-End Encryption。
- Client → Cloudflare:透過 Cloudflare Proxy 以 https 加密傳輸。
- Cloudflare → Nginx (Origin Server):使用你在伺服器上配置的 Cloudflare Origin SSL 進行加密,實現 End-to-End Encryption。
- Nginx → Backend http Server:Nginx 會將請求解密後,再轉發給backend (http)。