解决 n8n 显示 Connection lost 的错误

我刚装的 n8n 实例,创建 workflow 的时候右上角提示 Connection lost

1
2
You have a connection issue or the server is down.
n8n should reconnect automatically once the issue is resolved.

n8n show connection lost

先说一下我的环境,我是使用 docker 安装的 n8n,然后使用了 Nginx 进行的反代,不是使用官方提供的带 Traefik 的 docker compose 文件。

搜索了一下,发现是 n8n 后端的检测方式的问题,可以修改为使用 websocket 检测的方式:

在 docker-compose.yaml 中加入 N8N_PUSH_BACKEND=websocket

1
2
3
4
5
6
7
8
9
10
11
12
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
# ...
# 添加下面这一行
- N8N_PUSH_BACKEND=websocket
# ...

然后在 Nginx 中的反代部分启用 websocket 的支持

1
2
3
4
5
6
7
8
9
10
11
12
location / {
proxy_pass http://127.0.0.1:5678;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;

# 添加下面三行
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

重启 n8n

1
2
docker compose down 
docker compose up -d

以及重载 nginx

1
2
nginx -t
nginx -s reload

然后就可以了

n8n error fixed