Fix n8n 'Connection Lost' and Webhook URLs Behind a Proxy
Описание и применение
При размещении n8n за обратным прокси веб‑хуки показывали localhost и внутренний порт, а редактор постоянно отображал «Connection lost». Настройка переменной N8N_WEBHOOK_URL, правильная конфигурация WebSocket и установка N8N_PROXY_HOPS исправили проблему.
Задача
When n8n is placed behind a reverse proxy, the editor shows a persistent "Connection lost" badge and webhook URLs contain localhost or the internal port, making them unusable from outside.
Результат
After applying the environment variable and proxy configuration changes, webhook URLs no longer expose localhost or the internal port, and the editor’s live connection remains stable.
Рабочий процесс
- Set N8N_WEBHOOK_URL (or WEBHOOK_URL for older n8n) to https://n8n.example.com/ in the Docker Compose environment and recreate the container.
- Configure the reverse proxy to forward WebSocket upgrades: add proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; and preserve the original Host header.
- Set N8N_PROXY_HOPS=1 so n8n trusts the X-Forwarded-* headers from the proxy.
- Verify that webhook URLs in the editor start with the public domain and that the "Connection lost" badge disappears.
Доказательства
Set N8N_WEBHOOK_URL=https://n8n.example.com/ (or WEBHOOK_URL before n8n 2.30.0) and recreate the container with docker compose up -d.
The proxy has to pass WebSocket upgrades (Upgrade and Connection headers over HTTP/1.1) and keep the original Host.
Set N8N_PROXY_HOPS=1 for one proxy, so n8n trusts the X-Forwarded-* headers.
Webhook URLs now read https://n8n.example.com/webhook/... with no port.
- Дата записи: 2026-10-18T09:41:01.650Z