大家好,
我正在通過 Docker Compose 在 Plesk (Ubuntu 20.04, Plesk Obsidian 18.0.78) 上自託管 n8n,以 nginx 作為 Docker 前面的反向代理。
設定:
- n8n 官方 Docker 映像 (n8nio/n8n)
- 反向代理:Plesk 的 nginx (代理到 Apache,然後代理到 Docker 容器的 5678 埠)
- 域名:擁有自己 SSL 的子域名 (透過 Plesk 使用 Let’s Encrypt)
已設定的環境變數:
N8N_HOST=bot.publicides.com
N8N_PORT=5678
N8N_PROTOCOL=https
WEBHOOK_URL=https://bot.publicides.com/
N8N_SECURE_COOKIE=false
N8N_TRUST_PROXY=true
N8N_PROXY_HOPS=2
N8N_PUSH_BACKEND=sse
N8N_EDITOR_BASE_URL=https://bot.publicides.com/
已新增的 Nginx 其他指令:
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header Host $host;
proxy_pass_request_headers on;
問題:
任何即時編輯器操作 (執行前一個節點、測試此觸發器,甚至只是開啟執行選項卡) 都失敗,在 UI 中顯示「工作流程執行時出現問題 — 與伺服器的連線已中斷」。
Docker 日誌顯示此重複出現的錯誤:
Origin header 與預期的來源不相符。(Origin: “undefined” → “N/A”,預期:“undefined” → “undefined”,協議:“undefined”)
ResponseError: Invalid origin!
at Push.handleRequest (/usr/local/lib/node_modules/n8n/src/push/index.ts:157:10)
at /usr/local/lib/node_modules/n8n/src/push/index.ts:112:17
at Layer.handleRequest (…router/lib/layer.js:152:17)
…
at /usr/local/lib/node_modules/n8n/src/auth/auth.service.ts:158:18
我已排除的項目:
- 伺服器資源正常 (RAM ~72% 使用但有充足空間,CPU 低,磁碟使用率低)
- 不是瀏覽器/快取問題 — 在無痕模式、不同瀏覽器、不同裝置和行動數據而非 WiFi 中出現相同錯誤
- Docker 容器已啟動且健康狀態良好 (docker ps 確認「Up」)
- Webhooks 工作正常 — 手動 curl POST 到生產 webhook URL 傳回 {“message”:“Webhook call received”},工作流程端到端執行正確 (透過目標 Google Sheet 被更新確認)
- 域名未透過 Cloudflare 代理 (僅限 DNS / 灰雲)
因此,透過 webhook 的實際工作流程執行完美運作 — 僅有即時編輯器的 WebSocket/SSE push 連線失敗,似乎因為 nginx 和 n8n 的驗證服務之間某處的 Origin 標頭不相符而被拒絕。
有人在 Plesk 的 nginx 設定中遇到過這個特定的「Invalid origin」push 錯誤嗎?是否需要額外的環境變數或 nginx 指令來正確轉發/設定 push 端點的 Origin 標頭?
預先謝謝!