Connection Lost using NGINX Reverse Proxy n8n 1.16

I’m trying to setup n8n on my VPS that uses HestiaCP as Controler Painel. So I installed n8n by npm and made a reverse proxy from n8n.domain.com to my VPS_IP:5678. Everything looks nice, I can access n8n by my domain and my VPS_IP:5678, but when using the domain says Connection Lost all time, I can only use without the erro message by accessing it from VPS_IP:5678. I’ve tryied everything I found about, but nothing worked…

My NGINX reverse proxy is config like this:

server {
	listen      154.49.246.121:80;
	server_name n8n.snect.com.br www.n8n.snect.com.br;
	error_log   /var/log/apache2/domains/n8n.snect.com.br.error.log error;

	include /home/pedro/conf/web/n8n.snect.com.br/nginx.forcessl.conf*;

	location ~ /\.(?!well-known\/|file) {
		deny all;
		return 404;
	}

	location / {
		proxy_pass http://154.49.246.121:5678;
		proxy_http_version 1.1;
        proxy_set_header Connection '';
        proxy_set_header Host $host;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;

		location ~* ^.+\.(css|htm|html|js|json|xml|apng|avif|bmp|cur|gif|ico|jfif|jpg|jpeg|pjp|pjpeg|png|svg|tif|tiff|webp|aac|caf|flac|m4a|midi|mp3|ogg|opus|wav|3gp|av1|avi|m4v|mkv|mov|mpg|mpeg|mp4|mp4v|webm|otf|ttf|woff|woff2|doc|docx|odf|odp|ods|odt|pdf|ppt|pptx|rtf|txt|xls|xlsx|7z|bz2|gz|rar|tar|tgz|zip|apk|appx|bin|dmg|exe|img|iso|jar|msi|webmanifest)$ {
			try_files  $uri @fallback;

			root       /home/pedro/web/n8n.snect.com.br/public_html;
			access_log /var/log/apache2/domains/n8n.snect.com.br.log combined;
			access_log /var/log/apache2/domains/n8n.snect.com.br.bytes bytes;

			expires    max;
		}
	}

	location @fallback {
		proxy_pass http://154.49.246.121:5678;
	}

	location /error/ {
		alias /home/pedro/web/n8n.snect.com.br/document_errors/;
	}

	include /home/pedro/conf/web/n8n.snect.com.br/nginx.conf_*;
}

Prints as my n8n looks like in both cases:

As I’m running n8n via npm, I’m using pm2 to run it, and I used this comand to start it:

WEBHOOK_URL="https://n8n.snect.com.br/" WEBHOOK_TUNNEL_URL="https://n8n.snect.com.br/" VUE_APP_URL_BASE_API="https://n8n.snect.com.br/" GENERIC_TIMEZON="America/Sao_Paulo" N8N_HOST="n8n.snect.com.br" N8N_PROTOCOL="https" pm2 restart n8n --update-env

If someone could help my I would be glad, even it’s all working fine to send requests to n8n.domain.com, I would like to access and use editor using the domain, since this is easier to access from device, remember the vps ip kind of sucks to me. :sweat_smile:

Information on your n8n setup

  • **n8n version:1.16.0
  • **Database:SQLite
  • **Running n8n via:npm
  • **Operating system:Ubuntu 22.04

Hey @pedroepif,

Welcome to the community :raised_hands:

Self hosting n8n is considered an advanced feature so our support is fairly limited when it comes to things outside of the n8n application. In this case though the issue is with your nginx configuration, It is not configured to support websockets.

Try using something like the below, This may need further tweaks to fit your environment but should get you closer.

server {
	listen      154.49.246.121:80;
	server_name n8n.snect.com.br www.n8n.snect.com.br;
	error_log   /var/log/apache2/domains/n8n.snect.com.br.error.log error;

	include /home/pedro/conf/web/n8n.snect.com.br/nginx.forcessl.conf*;

	location ~ /\.(?!well-known\/|file) {
		deny all;
		return 404;
	}

	location / {
		proxy_pass http://154.49.246.121:5678;
		proxy_http_version 1.1;
		proxy_set_header Connection 'Upgrade';
		proxy_set_header Upgrade $http_upgrade;

		location ~* ^.+\.(css|htm|html|js|json|xml|apng|avif|bmp|cur|gif|ico|jfif|jpg|jpeg|pjp|pjpeg|png|svg|tif|tiff|webp|aac|caf|flac|m4a|midi|mp3|ogg|opus|wav|3gp|av1|avi|m4v|mkv|mov|mpg|mpeg|mp4|mp4v|webm|otf|ttf|woff|woff2|doc|docx|odf|odp|ods|odt|pdf|ppt|pptx|rtf|txt|xls|xlsx|7z|bz2|gz|rar|tar|tgz|zip|apk|appx|bin|dmg|exe|img|iso|jar|msi|webmanifest)$ {
			try_files  $uri @fallback;

			root       /home/pedro/web/n8n.snect.com.br/public_html;
			access_log /var/log/apache2/domains/n8n.snect.com.br.log combined;
			access_log /var/log/apache2/domains/n8n.snect.com.br.bytes bytes;

			expires    max;
		}
	}

	location @fallback {
		proxy_pass http://154.49.246.121:5678;
	}

	location /error/ {
		alias /home/pedro/web/n8n.snect.com.br/document_errors/;
	}

	include /home/pedro/conf/web/n8n.snect.com.br/nginx.conf_*;
}

Worked! Now I can use my n8 by n8n.domain.com, I will try to make a full guide for who wanna self-host n8n in a HestiaCP enviroment!

1 Like