DNS 與 Cloudflare
NexCMP 需要一個 DNS 名稱——其主網域——並以兩種模式運作。
模式 A:DNS 直接指向伺服器
- 建立 A 記錄
cloud.example.com → <server public IPv4>(如果伺服器有 IPv6,則建立 AAAA 記錄)。 - 選用(若您有使用):
admin.cloud.example.com與partner.cloud.example.com指向相同的 IP。 - 執行(或重新執行)installer。它會看到名稱解析為伺服器自己的公開 IP,並透過連接埠 80 上的 HTTP-01 驗證取得 Let's Encrypt 憑證。
模式 B:網域由 Cloudflare 代理
使用橘色雲朵(Proxied)建立相同的記錄。安裝程式會偵測到該名稱僅解析為 Cloudflare 位址,並切換至 Cloudflare 模式:
- nginx 仍會監聽您伺服器上的 80/443;
- 訪客的真實 IP 是從
CF-Connecting-IP標頭讀取 — 僅限來自 Cloudflare 公開 IP 範圍的連線,因此其他人無法偽造; - 憑證是透過 Let's Encrypt 取得(Cloudflare 會將驗證轉發到您的原始伺服器);如果暫時無法這樣做,系統會建立自簽證書以讓「Full」模式運作,後續重新執行安裝程式即可升級至 Let's Encrypt。
您可以透過 --behind-cloudflare 強制使用此模式。
::: important 在 Cloudflare 中設定 SSL/TLS 模式 在 Cloudflare 中前往 SSL/TLS › Overview,一旦安裝程式回報取得 Let's Encrypt 憑證,請選擇 Full (strict)。若使用自簽證書,請使用 Full。Flexible 將會導致重新導向迴圈。 :::
TIP
如果啟用「Always Use HTTPS」,Cloudflare 會將驗證請求傳送到您原始伺服器的連接埠 443。安裝程式會先建立暫時的自簽證書,然後重試 Let's Encrypt 來處理此情況。
檢查
bash
dig +short cloud.example.com # A record (a Cloudflare address in mode B)
curl -I https://cloud.example.com/healthz
sudo certbot certificates # certificate name, domains and expiry憑證會透過 certbot 的計時器自動續約。續約使用 webroot /var/www/nexcmp-acme,因此連接埠 80 必須保持可連線(直接或透過 Cloudflare)。
常見問題
| 症狀 | 原因 | 修正方式 |
|---|---|---|
| 安裝程式顯示「DNS … does not point to … (nor to Cloudflare) — skipping nginx/TLS」 | DNS 記錄遺失、錯誤或尚未生效 | 修正記錄、等待生效後重新執行安裝程式。 |
瀏覽器在 Cloudflare 後方顯示 ERR_TOO_MANY_REDIRECTS | SSL 模式為 Flexible | 設定為 Full (strict)(或 Full)。 |
| Cloudflare 錯誤 525/526 | 原始伺服器憑證遭到拒絕 | 搭配自簽證書使用 Full,或搭配 Let's Encrypt 使用 Full (strict)。 |
| 記錄中顯示所有訪客都是 Cloudflare IP | 不在 Cloudflare 模式下 | 使用 --behind-cloudflare 重新執行安裝程式。 |
更多資訊請參閱 Installation errors。