N8n Connection Lost

Hi everyone

Describe the problem/error/question

Since the update I receive the Connection lost error in the editor. n8n is paired with traefik as reverse proxy. When n8n is set to use sse, the Docker logs show a invalid origin error. If I use the option websocket, n8n can not connect to the websocket.

##The stack configuration

services:
traefik:
image: “traefik”
restart: always
command:
- --api.insecure=true
- --providers.docker
- --providers.file.directory=/etc/traefik/dynamic
- --entryPoints.web.address=:80
- --entryPoints.websecure.address=:443
ports:
- “80:80”
- “443:443”
labels:
- “traefik.enable=true”
- “traefik.http.routers.traefik_https.rule=Host(traefik.${DOMAIN_NAME})”
- “traefik.http.routers.traefik_https.entrypoints=websecure”
- “traefik.http.routers.app.tls=false”
- “traefik.http.routers.traefik_https.tls=true”
- “traefik.http.routers.traefik_https.service=api@internal”
volumes:
- ${DATA_FOLDER}/certs/certs:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
- /traefik/dynamic_conf.yml:/etc/traefik/dynamic/dynamic_conf.yml:ro
n8n:
image: n8nio/n8n
restart: always
ports:
- “127.0.0.1:5678:5678”

labels:
  - traefik.enable=true
  - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`) || Host(`${SUBDOMAIN3}.${DOMAIN_NAME3}`)
  - traefik.http.routers.n8n.tls=true
  - traefik.http.routers.n8n.entrypoints=web,websecure
  - traefik.http.middlewares.n8n.headers.SSLRedirect=true
  - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
  - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
  - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
  - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
  - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
  - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
  - traefik.http.middlewares.n8n.headers.STSPreload=true
  - traefik.http.routers.n8n.middlewares=n8n@docker
  - traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto = https
  - traefik.wss.protocol=https
  
environment:
  - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
  - N8N_PORT=5678
  - NODE_ENV=production
  - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
  - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
  - N8N_DIAGNOSTICS_ENABLED=false
  - N8N_PUSH_BACKEND=sse
  - EXECUTIONS_DATA_PRUNE=true
  - EXECUTIONS_DATA_MAX_AGE=12
  - EXECUTIONS_TIMEOUT_MAX=7200
  - N8N_BLOCK_FILE_ACCESS_TO_N8N_FILES=false
  - N8N_SECURE_COOKIE=false
  - N8N_RUNNERS_ENABLED=true
  - N8N_PROXY_HOPS=1
  

volumes:
  - /root/.n8n:/home/node/.n8n

##Additional information
A certificate is proxied using a functionality of a firewall.

Information on your n8n setup

  • **n8n version: 1.90.2
  • **Database (default: SQLite): SQLite
  • **n8n EXECUTIONS_PROCESS setting (default: own, main): own,main
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • **Operating system: Debian 11

Thanks in advance for your help.

I have had a similar issue when using SSE. It was fixed by enabling WSS in the reverse proxy and using that in n8n.
Is there a reason you are not using WSS?

Thanks for your reply.
I had some trouble in prior configurations and sse worked without any issue. So i used sse.
I dont mind using sse or wss. If there is a way to use wss, I would prefer using it.

I guess I do not see the error in my config. If you got a known good I’d like to compare those to find my mistakes.

Thanks in advance

The docs/github has some examples I think there is also a traefik example.

Ok, I cross checked with the official guide and some other guides. I still can not find my error. In the DevTool of the browser, I still receive:
WebSocket connection to ‘wss://n8n.mydomain.de/rest/push?pushRef=xikicjws6n’ failed

Traefik shows no error in its logs.

I’ve found my error. It was a misconfiguration in the WAF which blocked the websocket. After enabling websocket passthrough everything is working fine again.

Thank for your help.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.