N8n accessible via URL, but constantly shows “Connection lost” at the top

Hi everyone,

I recently set up n8n on an Ubuntu server and configured it to run as a systemd service. The instance is reachable via my custom domain (e.g. https://n8n-roasted.kaffie.co), but when I open the page, I keep seeing a “Connection lost” message at the top. The UI loads, but it seems like the frontend can’t maintain a stable connection with the backend.

What I’ve done so far:

  • I created a systemd service at /etc/systemd/system/n8n.service with the following content:
[Unit]
Description=n8n service
After=network-online.target
Wants=network-online.target

[Service]
WorkingDirectory=/home/n8n
Environment="N8N_HOST=0.0.0.0"
Environment="N8N_PORT=5678"
Environment="N8N_EDITOR_BASE_URL=https://n8n-roasted.kaffie.co"
Environment="N8N_WEBHOOK_URL=https://n8n-roasted.kaffie.co"
Environment="N8N_SECURE_COOKIE=true"
Environment="N8N_RUNNERS_ENABLED=false"
Environment="N8N_PROTOCOL=https"
ExecStart=/usr/bin/env n8n start
Restart=always
RestartSec=10
Type=simple
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
  • I ran systemctl daemon-reload, systemctl enable n8n, and started the service.
  • In the browser, the n8n UI loads fine at https://n8n-roasted.kaffie.co, but the “Connection lost” warning stays visible at the top.
  • Logs show n8n ready on 0.0.0.0, port 5678, so the backend seems to be running without crashing.

What I see in logs:

No fatal errors, just some warnings about file permissions and deprecated environment variables. But nothing that clearly points to this frontend connection issue.

My questions:

  1. Are there any additional environment variables needed to fix this issue (like for websockets or proxies)?
  2. Could this be caused by setting N8N_SECURE_COOKIE=true without using a reverse proxy with HTTPS properly configured?
  3. What’s the best way to resolve the “Connection lost” issue and ensure proper communication between the frontend and backend?

Thanks in advance for any help or suggestions!

hello @Floreal_Animatie

Never tried to set it as a system service… easier and faster to set it as a dockerized service (and more secure also). But that kind of issue usually means there is an issue with the websocket

Hi @Floreal_Animatie,

I had the same Issue regarding connection lost.

I’m running n8n also as a service, but with apache2 as proxy installed.

As long, as I had no WebSocket Rewrite in my site file, there was the same behavior like yours.

This site config works fine now:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName ****.com
    
    # Damit der Hostname korrekt an n8n weitergereicht wird:
    ProxyPreserveHost On

    # Keine offenen Proxy-Anfragen erlauben
    ProxyRequests Off

    # Standard-Proxy-Weiterleitung
    ProxyPass / http://127.0.0.1:5678/
    ProxyPassReverse / http://127.0.0.1:5678/

    # WebSockets weiterleiten (falls n8n/Plugins das benötigen)
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/(.*) ws://127.0.0.1:5678/$1 [P,L]

   SSLCertificateFile /etc/letsencrypt/live/****.com/fullchain.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/****.com/privkey.pem
   Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Maybe this helps you find a solution for your problem

3 Likes

I think you’re in the right direction. Do you have suggestions on how to make this work on NGINX?

I’m sorry, but I’m not fit when it comes to NGINX. Maybe this thread is what you are searching for: Connection lost: You have a connection issue or the server is down. n8n should reconnect automatically once the issue is resolved - #28 by cehojac

Thank you this works for me on Apache2 :saluting_face: