---
title: "自訂域名與 HTTPS"
description: "為 Calends 綁定自己的域名：Cloudflare 的 custom_domain 路由或 Docker 前方的反向代理，以及更換域名時 Passkey 與連結的注意事項。"
lang: "zh-HK"
version: "1.84.0"
url: "https://docs.calends.date/zh-hk/self-host/custom-domain/"
markdown_url: "https://docs.calends.date/zh-hk/self-host/custom-domain.md"
section: "自託管"
llms_index: "https://docs.calends.date/llms.txt"
llms_full: "https://docs.calends.date/llms-full.txt"
agents_guide: "https://calends.date/AGENTS.md"
---

# 自訂域名與 HTTPS

> 為 Calends 綁定自己的域名：Cloudflare 的 custom_domain 路由或 Docker 前方的反向代理，以及更換域名時 Passkey 與連結的注意事項。

- Canonical page: https://docs.calends.date/zh-hk/self-host/custom-domain/
- Markdown source: https://docs.calends.date/zh-hk/self-host/custom-domain.md
- Calends version: v1.84.0

需要使用自己的域名存取帳本時，按本頁設定 HTTPS，並更新日曆、MCP 與登入設定。

1. 決定新域名，並按部署方式設定下方的路由或反向代理。
2. 將 `SITE_URL` 設為 `https://calends.example.com`，重新部署或重建容器。
3. 使用新域名登入，核對 HTTPS、Passkey、日曆與 MCP 接入。

## Cloudflare

在 `wrangler.jsonc` 加入 `routes`，將域名以 `custom_domain` 綁定至 Worker。該域名須已託管於你的 Cloudflare 帳號內：

```jsonc
"routes": [{ "pattern": "calends.example.com", "custom_domain": true }],
```

接著重新部署：

```bash
npm run deploy
```

Cloudflare 會自動建立 DNS 記錄與憑證。你亦可在控制台的 Worker 設定新增自訂域名，效果相同。

建議同時把 `vars` 中的 `SITE_URL` 更新為新域名，見[設定項](https://docs.calends.date/zh-hk/self-host/config.md)。

## Docker

Calends 本身僅提供 HTTP。公網存取時須置於反向代理後方，由代理負責 HTTPS。一行安裝指令碼只會啟動本機服務，不會設定域名或網頁伺服器。

Calends 會自動判斷訪客 IP：只有來自本機、內網或 Cloudflare 的連線才讀取 `X-Forwarded-For`，由右至左取第一個不受信任的位址。`TRUST_PROXY` 通常留空，Caddy、Traefik 與 Cloudflare Tunnel 可直接使用。Nginx 必須加上 `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;`，否則訪客可能偽造登入限速所用的 IP。

連接埠應只對代理開放（`-p 127.0.0.1:8787:8787`）；systemd 則設 `HOST=127.0.0.1`。若不經代理也能連到 Calends，請設 `TRUST_PROXY=off`：同一內網的訪客可以偽造該標頭；當 Docker 將連線來源顯示為閘道（Docker Desktop、rootless Docker、部分 IPv6 連接埠對應）時，公網訪客亦可能偽造。使用 Cloudflare 以外的 CDN 時，以逗號分隔的 IP/CIDR 清單追加其位址段，例如 `TRUST_PROXY=192.0.2.0/24,198.51.100.7`；若不加入，所有訪客都會共用 CDN 位址。

舊版數字值（如 `1`、`2`）現按自動判斷處理，不再代表代理層數。Cloudflare 部署不使用此變數。登入限速不影響已登入的會話。

**Caddy**（自動申請憑證）：

```text
calends.example.com {
  reverse_proxy 127.0.0.1:8787
}
```

**Nginx**：

```nginx
server {
  listen 443 ssl;
  server_name calends.example.com;
  # ssl_certificate / ssl_certificate_key ...

  location / {
    proxy_pass http://127.0.0.1:8787;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}
```

內置助手的串流回覆附有 `X-Accel-Buffering: no` 回應標頭，Nginx 不會緩衝串流，回覆可即時顯示。

如只於本機或內網使用，可直接存取 `http://<IP>:8787`。瀏覽器只允許在 HTTPS 或 `localhost` 環境下使用 Passkey，以 IP 存取時只能用密碼登入。

## 更換域名時

- **Passkey** 綁定在域名上，換域名後舊 Passkey 無法使用。請先用密碼登入，再到「設定 → 安全」重新新增。
- **日曆訂閱連結**與提醒內的連結採用站點網址。有設 `SITE_URL` 時改成新域名；未設時用新域名開啟一次應用即可。已訂閱的日曆須替換為新連結。
- **MCP 用戶端**的網址改為新域名，令牌無須更換。
- 更換域名不會影響任何帳本資料。

Cloudflare 部署可以逗號分隔的 `OLD_HOSTS` 列出舊域名：保留舊 Worker 路由並將 `SITE_URL` 設為新網址後，舊頁面會傳回 HTTP 301 重導，API、MCP 與 ICS 仍可存取。Docker 執行入口不會透傳此變數。

---

## Related Pages & Global AI Discovery

To explore broader context beyond this page, fetch any of the Markdown or plain-text resources below directly:

### Same Section (自託管)
- [Cloudflare Workers + D1](https://docs.calends.date/zh-hk/self-host/cloudflare.md)
- [Docker](https://docs.calends.date/zh-hk/self-host/docker.md)
- [設定項](https://docs.calends.date/zh-hk/self-host/config.md)
- [自訂域名與 HTTPS](https://docs.calends.date/zh-hk/self-host/custom-domain.md) *(current)*
- [升級](https://docs.calends.date/zh-hk/self-host/upgrade.md)
- [本機開發](https://docs.calends.date/zh-hk/self-host/development.md)
- [參與翻譯](https://docs.calends.date/zh-hk/self-host/translate.md)

### Reading Order
- Previous: [設定項](https://docs.calends.date/zh-hk/self-host/config.md)
- Next: [升級](https://docs.calends.date/zh-hk/self-host/upgrade.md)

### Global Calends Resources
- Read-only Docs MCP Server (zero auth Streamable HTTP): https://docs.calends.date/mcp
- Complete Docs Index (all 37 topics with `.md` links): https://docs.calends.date/llms.txt
- Complete English Docs Bundle (single file): https://docs.calends.date/llms-full.txt
- Complete Simplified Chinese Docs Bundle: https://docs.calends.date/llms-zh.txt
- Docs AI Agent Guide: https://docs.calends.date/AGENTS.md
- Product Website Overview (Markdown): https://calends.date/zh-hk/index.md
- Product LLMs Index & Full Reference: https://calends.date/llms.txt | https://calends.date/llms-full.txt
- Deployment & MCP Agent Guide (AGENTS.md): https://calends.date/AGENTS.md
- FAQ & Calends vs Wallos Comparison (Markdown): https://calends.date/en/faq.md | https://calends.date/en/compare.md
- Complete Changelog (Markdown): https://calends.date/en/releases.md
