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 可以在编辑器 UI 中显示它,并向外部服务注册正确的 webhook URL。

¥set the webhook URL manually with the WEBHOOK_URL environment variable so that n8n can display it in the editor UI and register the correct webhook URLs with external services.

  • N8N_PROXY_HOPS 环境变量设置为 1

¥Set the N8N_PROXY_HOPS environment variable to 1.

  • 在请求路径上的最后一个代理中,设置以下标头以传递有关初始请求的信息:

¥On the last proxy on the request path, set the following headers to pass on information about the initial request:

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.