Skip to content

配置带有反向代理的 n8n Webhook(Configure n8n webhooks with reverse proxy)#

n8n 通过组合 N8N_PROTOCOLN8N_HOSTN8N_PORT 来创建 webhook URL。如果 n8n 运行在反向代理后面,这将无法正常工作。这是因为 n8n 在内部运行在端口 5678,而反向代理在端口 443 将其暴露给网络。

🌐 n8n creates the webhook URL by combining N8N_PROTOCOL, N8N_HOST and N8N_PORT. If n8n runs behind a reverse proxy, that won't work. That's because n8n runs internally on port 5678 but the reverse proxy exposes it to the web on port 443.

当 n8n 运行在反向代理之后时,请务必执行以下操作:

🌐 When running n8n behind a reverse proxy, it's important to do the following:

  • 使用 WEBHOOK_URL 环境变量手动设置 webhook URL,以便 n8n 可以在编辑器界面中显示它,并向外部服务注册正确的 webhook URL。
  • N8N_PROXY_HOPS 环境变量设置为 1
  • 在请求路径上的最后一个代理中,设置以下标头以传递有关初始请求的信息:

1
2
export WEBHOOK_URL=https://n8n.example.com/
export N8N_PROXY_HOPS=1
Refer to Environment variables reference for more information on this variable.