Skip to content

Guide

Fix n8n "Connection lost" behind a reverse proxy

The n8n editor opens, the workflows are there, but the top right corner says "Connection lost". The warning means the editor lost its WebSocket at /rest/push, the channel the server uses to send events to the screen, and the one dropping that connection is almost always the reverse proxy in front of n8n. This guide shows the two causes we reproduced, how to tell which one you have, and the configuration that worked on Nginx, Caddy and Traefik.

On this page
  1. The two causes
  2. How to confirm the cause
  3. Nginx
  4. Caddy
  5. Traefik
  6. What about N8N_PROXY_HOPS and WEBHOOK_URL?
  7. What the test did not cover

The test was run on December 6, 2026 with n8n 3.4.4 (docker.n8n.io/n8nio/n8n:3.4.4) in a clean Ubuntu 24.04.5 LTS container with Docker 29.10.1. In front of n8n, one at a time: Nginx 1.30.8, Caddy 2.11.9 and Traefik v3.8.0. The editor was opened in Chrome, with the console read through DevTools.

n8n 3.4.4 editor with a workflow open and the Connection lost warning with an orange triangle in the top right corner, where the Publish button normally is

The two causes

On n8n 3.4.4, GET /rest/settings returns pushBackend set to websocket. The editor opens wss://n8n.example.com/rest/push?pushRef=..., and the server only accepts the connection when both conditions below hold.

1. The proxy passes the WebSocket upgrade through. Nginx does not forward the Upgrade and Connection headers unless you tell it to. With a location that only has proxy_pass and the X-Forwarded-* headers, the request reached n8n as a plain GET, and n8n answered 401 Unauthorized. In the Chrome console, the editor retried after 1, 2, 4 and 8 seconds. In this case the corner warning did not show up during the 30-second test, because the editor spent the whole time between attempts; the clear signal was the console:

text
[WebSocketClient] Connection error: Event
[WebSocketClient] Connection lost, code=1006
[WebSocketClient] Attempting to reconnect in 1000ms

2. The browser's Origin matches the host n8n receives. n8n compares the Origin header with X-Forwarded-Host (or Forwarded) and, without them, with Host. By default, Nginx sends the proxy_pass address as Host. With the upgrade right but without proxy_set_header Host $host, the connection opened, n8n sent Invalid origin! and closed it with code 1008. That is the case in the image above. The n8n log records the mismatch:

text
Origin header does NOT match the expected origin. (Origin: "https://n8n.example.com" -> "n8n.example.com", Expected: "n8n:5678" -> "n8n:5678", Protocol: "https")

In the Chrome console:

text
[WebSocketClient] Connection lost, code=1008

N8N_HOST is not part of that comparison. Changing N8N_HOST, N8N_WEBHOOK_URL or N8N_PROXY_HOPS does not fix "Connection lost".

How to confirm the cause

Start with the browser console (F12, Console tab) while the editor is open: repeated code=1006 points to a blocked upgrade; code=1008 points to the Origin check. Then the n8n log:

bash
docker compose logs n8n | grep "Origin header does NOT match"

A line here means cause 2. Without signing in, you can test the upgrade from the VPS or from your computer:

bash
curl --http1.1 -sS -o /dev/null -w '%{http_code}\n' --max-time 3 \
  -H 'Connection: Upgrade' -H 'Upgrade: websocket' \
  -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
  "https://n8n.example.com/rest/push?pushRef=test"

Replace n8n.example.com with your domain. --http1.1 is required: without it, curl negotiates HTTP/2 with proxies that support it, such as Caddy and Traefik, and no upgrade happens. In the test, the proxy that blocked the upgrade answered 401. The proxies that passed it answered 101 (and curl ends with Operation timed out, which is expected, because the connection stays open).

Nginx

This server block passed both tests: 101 from curl and the editor connected, with no "Connection lost", for almost 3 minutes.

/etc/nginx/conf.d/n8n.conf
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    server_name n8n.example.com;
    ssl_certificate     /etc/nginx/certs/n8n.crt;
    ssl_certificate_key /etc/nginx/certs/n8n.key;

    location / {
        proxy_pass http://n8n:5678;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
  • proxy_http_version 1.1, Upgrade and Connection fix cause 1. The map sends close when the request is not an upgrade.
  • proxy_set_header Host $host fixes cause 2.
  • proxy_pass http://n8n:5678 is for Nginx running in a container on the same network as n8n. With Nginx installed on the host, use http://127.0.0.1:5678 and publish the port on loopback only ("127.0.0.1:5678:5678").

After editing, check and reload. With Nginx in a container, in the same Compose project as n8n:

bash
docker compose exec nginx nginx -t
docker compose exec nginx nginx -s reload

With Nginx installed on the host, the equivalent is sudo nginx -t && sudo systemctl reload nginx.

Caddy

Caddy's reverse_proxy passes WebSockets through with no extra settings and sends X-Forwarded-Host with the original domain, which is what n8n compares with Origin. This Caddyfile returned 101 and kept the editor connected:

Caddyfile
{$N8N_DOMAIN} {
	reverse_proxy n8n:5678
}

If "Connection lost" shows up with Caddy, look for another proxy along the way, such as a CDN or a second proxy, and repeat the curl test against each one. For 502 or certificate errors in Caddy, see Fix Caddy 502 Bad Gateway and HTTPS errors with Docker.

Traefik

Traefik also passes WebSockets through by default and keeps the request's original host. With the Docker provider, these labels on the n8n service returned 101:

docker-compose.yml
services:
  n8n:
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`n8n.example.com`)
      - traefik.http.routers.n8n.entrypoints=websecure
      - traefik.http.routers.n8n.tls=true
      - traefik.http.services.n8n.loadbalancer.server.port=5678

In the test, Traefik used its default certificate, with no ACME resolver. In production, the tls.certresolver label points to your Traefik resolver. Choosing between the two proxies is covered in Traefik vs Caddy on a Docker VPS.

What about N8N_PROXY_HOPS and WEBHOOK_URL?

Both variables show up in every guide about n8n behind a proxy, but they deal with something else. In the test, neither one changed the WebSocket result.

  • N8N_PROXY_HOPS=1 makes n8n trust the X-Forwarded-For header from one proxy. With 0, the log showed ValidationError: The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default).. The message itself warns that the rate limiter then cannot identify each user. With two proxies in a row, the value is 2.
  • N8N_WEBHOOK_URL sets the public address of webhooks. Without it, the urlBaseWebhook of n8n 3.4.4 was https://n8n.example.com:5678/, with the internal port. With N8N_WEBHOOK_URL=https://n8n.example.com/, it was https://n8n.example.com/. The old name, WEBHOOK_URL, still works on 3.4.4, but startup warns WEBHOOK_URL -> Use N8N_WEBHOOK_URL instead.

The n8n environment block used in every test:

docker-compose.yml
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n:3.4.4
    environment:
      - N8N_HOST=${N8N_DOMAIN}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - N8N_WEBHOOK_URL=https://${N8N_DOMAIN}/
      - N8N_PROXY_HOPS=1

The webhook showing localhost:5678 is covered in The n8n webhook shows localhost:5678. The full installation, with PostgreSQL, the runner and Caddy, is in How to install n8n with Docker on a VPS, and the machine to run n8n on is at n8n VPS.

What the test did not cover

n8n ran with SQLite, without an external runner and without public certificates: Caddy used tls internal, Nginx a self-signed certificate and Traefik its default certificate. We did not test a CDN in front of the proxy, Nginx Proxy Manager, or the SSE push backend (N8N_PUSH_BACKEND=sse).