Connection Lost Issues

  • n8n version: Latest
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Unsure
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: unRAID

Hiya all!

I have recently setup N8N as a docker container on my unRAID home lab. I have reverse proxied it via Apache as I do for all my sites, but have notices I keep getting “Connection Lost - You have a connection issue or the server is down. n8n should reconnect automatically once the issue is resolved.”

Below is my Apache config:

# Redirect HTTP to HTTPS

<VirtualHost *:80>

ServerName n8n.domain.com

\# Redirect all HTTP traffic to HTTPS

Redirect permanent / https://n8n.domain.com/

ErrorLog ${APACHE_LOG_DIR}/n8n-http-error.log

CustomLog ${APACHE_LOG_DIR}/n8n-http-access.log combined

# HTTPS + reverse proxy to n8n

<VirtualHost *:443>

ServerName n8n.domain.com

SSLEngine on

SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem

SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem

ProxyPreserveHost On

\# Standard HTTP proxy to n8n

ProxyPass / http://10.0.1.112:5678/ retry=0

ProxyPassReverse / http://10.0.1.112:5678/

\# WebSocket support (n8n real-time execution)

ProxyPass /ws/ ws://10.0.1.112:5678/ws/

ProxyPassReverse /ws/ ws://10.0.1.112:5678/ws/

\# Required headers

RequestHeader set X-Forwarded-Proto "https"

RequestHeader set X-Forwarded-Port "443"

\# Increase timeout for long-running workflows

ProxyTimeout 300

ProxyReceiveBufferSize 65536

ErrorLog ${APACHE_LOG_DIR}/n8n-error.log

CustomLog ${APACHE_LOG_DIR}/n8n-access.log combined

The config of my docker container is also below:

If anything else is needed or anyone has any ideas, please let me know.

Thanks!
Kian

@Kian_Walters Hello! I hope your having a good day!

Has this connection been working in the past or has it always failed?

I found a few similar issues in github, however none refrencing apache, but rather /rest/push/.

It seems in your configuration, you are proxying /ws/ to the backend, but n8n typically does this at /rest/push

You could always use sse through server sent events, but you probally want to just update the apache configuration.. You could use code such as this

# Redirect HTTP to HTTPS
<VirtualHost *:80>
    ServerName n8n.domain.com
    Redirect permanent / https://n8n.domain.com/
    ErrorLog ${APACHE_LOG_DIR}/n8n-http-error.log
    CustomLog ${APACHE_LOG_DIR}/n8n-http-access.log combined
</VirtualHost>

# HTTPS + Reverse Proxy to n8n
<VirtualHost *:443>
    ServerName n8n.domain.com

    # SSL Configuration
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem

    # Proxy Settings
    ProxyPreserveHost On

    # WebSocket Handling
    # Catches any WebSocket upgrade request on any path
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*)           ws://10.0.1.112:5678/$1 [P,L]

    # Standard HTTP Proxy
    ProxyPass / http://10.0.1.112:5678/ retry=0
    ProxyPassReverse / http://10.0.1.112:5678/

    # Required Headers for n8n
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"

    # Timeout for long-running workflows
    ProxyTimeout 300
    ProxyReceiveBufferSize 65536

    # Logging
    ErrorLog ${APACHE_LOG_DIR}/n8n-error.log
    CustomLog ${APACHE_LOG_DIR}/n8n-access.log combined
</VirtualHost>

Also run this after saving so it works properly

sudo a2enmod rewrite proxy proxy_http proxy_wstunnel ssl headers
sudo apache2ctl configtest
sudo systemctl restart apache2

Also, cool home lab setup it sounds like!

Hope this helps!

2 Likes

That fixed it, thanks so much! :slight_smile:

1 Like

Your welcome! Happy to help!

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