Connection Lost: Lost connection to the server

Describe the problem/error/question

I am trying to deploy n8n with docker and locally witn npm and in both situation I get always the error of “Connection lost” Lost connection with the server.

Running in Version 1.86.1

What is the error message (if any)?

Connection Lost. Lost connection to the server. There is no any error in the logs of the docker neither on the n8n.

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • dokker and npm.
  • Operating system:
  • npm running in Windows and docker in Ubuntu.

Hi,

Is this a connection lost in the upper right corner of the user interface (once your are logged in)?

You can reach the login page without any problems?

reg,
J.

Yes to both questions.

Hi,

Do you have any special security software installed or something like this? if it’s a local websocket connection it should not be a problem. Are you running recent versions?

Reg,
J.

No, no special software. Finally it has worked with N8N_PUSH_BACKEND=see. Something very strange.

1 Like

hi. same situation, always get “CONNECTION LOST” after installing upgrade version 1.86.2. Any indication? do you know why [quote=“Claudi, post:5, topic:99309”]
N8N_PUSH_BACKEND=see works?

[/quote]

If i recall, you need to enable websocket support in npm explicitly. Is that enabled?

Hi,
After upgrading to 1.94.1, facing this error.
Running on self hosted Digital Ocean droplet using docker.
This is my docker compose yml file :

services:
  n8n:
    image: n8nio/n8n
    container_name: n8n-app
#    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=n8n.mydomain.com
      - MODE_ENV=production
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.mydomain.com/
      - N8N_SECURE_COOKIE=false
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - N8N_RUNNERS_ENABLED=true
      - N8N_PROXY_HOPS=1
      - TZ=UTC+2
      - N8N_PUSH_BACKEND=sse
      - N8N_PUSH_BACKEND_WS=true  # Enable WebSocket for better stability
      - N8N_PUSH_BACKEND_WS_RECONNECT_TIMEOUT=5000  # Reconnect delay
      - N8N_PUSH_BACKEND_WS_KEEP_ALIVE_INTERVAL=20000  # Keep connection alive
#      - DB_TYPE=sqlite
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n_user
      - DB_POSTGRESDB_PASSWORD=n8n_password
    volumes:
      - /root/n8n/n8n_data:/home/node/.n8n  # Absolute path to ensure mounting
    user: "1000:1000" 
    depends_on:
      - postgres
  postgres:
    image: postgres:14
    container_name: n8n-postgres
    restart: always
    environment:
      - POSTGRES_DB=n8n
      - POSTGRES_USER=n8n_user
      - POSTGRES_PASSWORD=n8n_password
    volumes:
      - /root/n8n/postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

volumes:
  postgres_data:

This is my nginx config file :

server {
    server_name n8n.mydomain.com;

    # Document root if you need to serve static files or custom error pages
    root /var/www/n8n;

    # Custom error page (optional)
    error_page 502 403 /custom_error.html;

    # Proxy all requests to the Flask app running on port 5000
    location / {
        proxy_pass http://localhost:5678;
        proxy_set_header Upgrade $http_upgrade; # websocket support
        proxy_set_header Connection "upgrade";  # websocket support
        proxy_set_header Host $host;
        proxy_set_header Connection '';
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
        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 $scheme;


       # Fix Lost Connection Issue
        proxy_connect_timeout 3600;
        proxy_send_timeout 3600;
        proxy_read_timeout 3600;
        send_timeout 3600;

    }

    # Serve the custom error page if needed
    location = /custom_error.html {
        internal;
    }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/n8n.mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/n8n.mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

How can I solve this?

I’ve managed to solve this by removing the following :slight_smile:

 - N8N_PUSH_BACKEND=sse
1 Like

they have relase an hotfix

After upgrade to 1.95.3 it is failing again and now It doesn´t work again…Any help?

i have no issue after the past hotfix

On apache2, here is how to activate websocket :

<VirtualHost *:80>
        ServerAlias YOURDOMAINNAMEHERE

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:5678/
        ProxyPassReverse / http://127.0.0.1:5678/

        # Forward client IP and other headers
        RemoteIPHeader X-Forwarded-For
        RequestHeader set X-Real-IP "%{REMOTE_ADDR}s"
        RequestHeader set X-Forwarded-Port "%{SERVER_PORT}s"

        # WebSocket settings (Proxy to docker container console)
        # https://community.n8n.io/t/connection-lost-warning/29966/7
        <Location /rest/push>
                ProxyPass "ws://127.0.0.1:5678/rest/push"
                ProxyPassReverse "ws://127.0.0.1:5678/rest/push"

                RewriteEngine on
                RewriteCond %{HTTP:Upgrade} =websocket [NC]
                RewriteCond %{HTTP:Connection} upgrade [NC]
                RewriteRule .* "ws://127.0.0.1:5678/rest/push" [P]
        </Location>
</VirtualHost>

So i just add the environment variable “N8N_PUSH_BACKEND=sse” in DockerCompose file, and add the line ’ RequestHeader set Origin “https://yourn8ndomain.xx” ’ to the reverse proxy VirtualHost config.

My n8n version is 1.105.0, reverse proxy server is Apache2 .

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