I updated n8n to 1.5 im getting connection lost

i updated n8n to 1.5 im getting connection lost @ Jan Oberhauser

Hey @Sale.Favourite_fab,

I suspect this could be down to the websocket change, Have you updated your reverse proxy (if you are using one) to support web sockets?

No I dont Change in nothing i just npm -g update

Hi @Sale.Favourite_fab

Not sure how to add wss in the config of nginx. but in the GUI there is a slider to enable it. So it does seem to be something specific you have to set to enable it.

1 Like

Hi @Sale.Favourite_fab, in addition to what @BramKn shared above for Nginx Proxy Manager, can you try updating the proxy_set_header Connection line when using a hand-crafted server block as suggested by @cuman over here? This seems to have done the job :slight_smile:

You could also switch back to server-sent events (this is the technology used by n8n before v1) if you prefer. To do so, youā€™d need to set the N8N_PUSH_BACKEND=sse environment variable and restart n8n to pick up the change.

2 Likes

I was having the same problem and enabling Websockets Support in the Nginx GUI fixed it for me.

5 Likes

I had the same issue after upgrading to 1.0.5

The sse fix proposed on Permanent "Connection lost" error for n8n next did the trick for me, as I am running Docker with Apacheā€™s reverse proxy.

@MutedJam do you foresee a future issue with not using the default websocket setting from now on?

PS: Looking for ā€œConnection Lostā€ on this forum top search field only shows results older than 1 year, unless you click ā€œMoreā€. So I was about to create yet another duplicate post for this question ā€¦ :sweat_smile:

Hey @jb8n,

v1 made the change from SSE to Websockets so I donā€™t expect this to change any time soon.

After going down a huge rabbit holeā€¦ This fixed it for me! THANK YOU!

4 Likes

To make it clear. WebSockets will be the only option in the future. So switching over is required at some point in the future anyway.

Hello!

I stumbled upon the same issue after updating to version 1.0.5.

Iā€™ve installed n8n with npm and am using NGINX reverse proxy.

Adding the following to my n8nā€™s sites-enabled config fixed the websocket connection issue for me:

    # Main location block with added Websockets support
    location / {
        proxy_pass http://nn_backend;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        client_max_body_size 50m;
        client_body_buffer_size 1m;
        proxy_read_timeout 600s;
        proxy_buffering off;
        proxy_cache off;
    }

    # Webhook location block with added Websockets support
    location ~ ^/(webhook|webhook-test) {
        proxy_set_header Connection '';
        chunked_transfer_encoding off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_buffering off;
        proxy_cache off;
        proxy_pass http://nn_backend;
    }

Since you were not sure how to add websocket support in the config of nginx, I hope this would help other people using n8n 1.x.x without issues.

Cheers!

6 Likes

Hi there,

I have the same issue but I use Apache2ā€¦ Iā€™ve enabled the mod_proxy_wstunnel but I canā€™t make it work. I guess I donā€™t have the right configuration.

Has anyone here with a similar environment succeeded?

Thank you.

Kind regards,

I have a separate post about it but cant get it figured out either.

Hey @Nicolas_Esteves,

Have you tried adding RewriteCond %(HTTP:Upgrade) websocket [NC] to your proxy settings?

Hi there,

Here is what I have:

    RewriteCond ${HTTP:Upgrade} websocket [NC]
    RewriteCond ${HTTP:Connection} upgrade [NC]
    RewriteRule .* "wss:/localhost:5680/$1" [P,L]

    ProxyPass               /wss/   wss://localhost:5680/
    ProxyPassReverse        /wss/   wss://localhost:5680/

    ProxyPass               /       http://localhost:5680/
    ProxyPassReverse        /       http://localhost:5680/

Clearly, Iā€™m ashamed to say that but, I have no idea what Iā€™m doing. Iā€™m not a newbie with Apache2 but this is the first time Iā€™m trying to use a websocket.

Any idea? Thank you.

PS: Iā€™ve tried many things, previous sample is just my last attempt.

Hi @jan,

I think Iā€™m going to use the ā€˜sseā€™ fix for the moment as Iā€™m really stuck. Do you think that would be possible to make sure a valid example for Apache is available before making websockets the only available option?

Thank you.

Kind regards,

Hey @Nicolas_Esteves,

It is tricky really, We could document it for Apache but then we would also have to document it for all of the other reverse proxies which would take time.

Did you try without the options below in your config file?

    RewriteRule .* "wss:/localhost:5680/$1" [P,L]

    ProxyPass               /wss/   wss://localhost:5680/
    ProxyPassReverse        /wss/   wss://localhost:5680/

I will see if I can free up some time to work out what is actually needed for Apache as it is not really something I use.

Alright so for anyone that needs it I have just spent a bit of time learning about Apache2 as a reverse proxy.

To get n8n up and running with Websockets in 1.0 below is an example config file that works when used with n8n in a container. This example is for HTTP so if you were using HTTPS you would need to make those changes.

<VirtualHost *:80>
        ServerName n8n.yourdomain.tld

        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*)           ws://172.17.0.1:5678/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /(.*)           http://172.17.0.1:5678/$1 [P,L]
        ProxyPassReverse /          http://n8n.yourdomain.tld
</VirtualHost>

This will need proxy, proxy_http, proxy_wstunnel and rewrite to work but as of right now on a clean Digital Ocean droplet using n8n 1.1.1 this works.

7 Likes

Thanks @Jon, I was close but couldnā€™t have made it work without your help, or at least not without losing a few extra hours! So thank you very much!

Hereā€™s the final solution, if it helps anyone else:

<VirtualHost *:80>
        # HTTP -> HTTPS
        ServerName n8n.domain.com

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
        ServerName n8n.domain.com

        SSLEngine       On
        SSLProxyEngine  On
        ProxyRequests   Off
        ProxyPreserveHost       On

        SSLCertificateFile      /etc/apache2/certs/2023_wildcard.domain.crt
        SSLCertificateKeyFile   /etc/apache2/certs/2023_wildcard.domain.key
        SSLCertificateChainFile /etc/apache2/certs/2023_wildcard.domain_inter.crt

        TimeOut 600
        KeepAliveTimeout 600

        SSLProxyVerify none
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off

        <Proxy *>
                Require all granted
        </Proxy>

        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*)           ws://localhost:5678/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /(.*)           http://localhost:5678/$1 [P,L]
        ProxyPassReverse /          http://n8n.domain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Have a nice day!

Kind regards,

5 Likes

Thank you @Nicolas_Esteves for sharing this.
After trying a long time to fix exactly the same issue, i came to your post and it seems to work :slight_smile:

But sporadically, I face problems that I canā€™t access to n8n at all with a browser error message:

Bad Gateway
The proxy server received an invalid response from an upstream server.

or

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

After refreshing, it will work most of the timeā€¦
Could it be that I have still some issues with my apache2 reverse proxy settings?
Does anybody knows how to fix this issue?
Thank you

Edit: It even fails sometimes if I load it locally over localhost:5678