Nginx configuration

Hi :wave:
I tried to install n8n on my server. I use nginx to make the bridge between n8n.mydomain and localhost:5678.
It works, I can access to the interface. The problem is that I have the message “Server connection could not be established. The server is down or there is a connection problem. It will reconnect automatically as soon as the backend can be reached.”
Is there a port to configure in addition to 5678?
Thanks

Hello,

hope that helps:

# How n8n should be made available. Gets by default also used to create the base of the webhook URL.
N8N_HOST="n8n.example.com"
N8N_PORT=443
N8N_PROTOCOL="https"

# If the Webhook URL is different because for example there is a reverse proxy in front of it and n8n does
# use port 4000 but is reachable from the outside via 443 it can be overwritten with:
WEBHOOK_TUNNEL_URL="https://n8n.example.com/"

# This URL gets used in the Frontend to tell it where the backend can be found
VUE_APP_URL_BASE_API="https://n8n.example.com/"

So the error you describe sounds to me like that either the environment variable VUE_APP_URL_BASE_API is not set correctly or n8n is not reachable.

Can you tell me what happens when you click on the “+” on the right side to create a node. Does the list contain any nodes?

I use the npm package.
I configure my file .profile like this :

export N8N_HOST="localhost"
export N8N_PORT=5000
export N8N_PROTOCOL="http"
export WEBHOOK_TUNNEL_URL="http://n8n.mydomain/" 
export VUE_APP_URL_BASE_API="http://n8n.mydomain/" 

n8n use well my .profile. I check it by changing port.

When I click on “+”, I can select and configure nodes. But when I try to execute, I get this message :
" Problem running workflow
There was a problem running the workflow:
No active connection to server. It is maybe down."

You could just try to access n8n locally. So set:

export VUE_APP_URL_BASE_API=“http://localhost:5000/”

And then open it also via that URL.

Btw. if you need the UI to be web-accessible you can have a look at this:

That should solve your problem. Because if you can see the nodes it means that the UI can reach the API. So everything is configured correctly in that regard. So then it is probably a problem with EventSource and how it does not work correctly. with your Nginx setup.

I will try to add proper documentation about that soon.

I’ didn’t see there was the same issue on github.
Thank’s for your help ! :pray:

To summarize a config that works on nginx for those who need while waiting for the doc :wink:

nano /etc/nginx/sites-available/cloud.example.com

server {
   listen 443 ssl;
   listen [::]:443 ssl;
}
server_name cloud.example.com;
location / {
   proxy_pass http://localhost:5678;
   proxy_set_header Connection '';
   proxy_http_version 1.1;
   chunked_transfer_encoding off;
   proxy_buffering off;
   proxy_cache off;
}
...

If not done before:

ln -s /etc/nginx/sites-available/cloud.example.com /etc/nginx/sites-enabled/cloud.example.com

nano .bashrc

# n8n
N8N_HOST="cloud.example.com"
N8N_PROTOCOL="https"
N8N_PORT="443"
VUE_APP_URL_BASE_API="https://cloud.example.com/"
WEBHOOK_TUNNEL_URL="https://cloud.example.com/"
source ~/.profile
systemctl restart nginx.service

Then just run n8n and you can access it from https://cloud.example.com/

3 Likes

Thanks a lot @Arnaud!

Will make it later much easier for me to add it to the documentation if you already did the most of the work :wink:

1 Like

I also put that here. It’s probably not the best way to launch n8n but it can help.

How to start automatically n8n with systemd:
nano /etc/systemd/system/n8n.service (the location depends on your os)

[Unit]
Description=n8n service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
User=**USER**
ExecStart=/usr/bin/node /usr/lib/node_modules/n8n/bin/n8n

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable n8n
systemctl start n8n
systemctl status n8n

(if it’s not working see the logs with journalctl -u n8n.service -e)

1 Like

@Arnaud Great, thanks! Yes, I think “not the best” is always better for people than not having any way at all :wink:

Have personally not the slightest idea about “systemd” or anything related. I am sure this solution is good enough for now and if something can get improved I hope at some point somebody will point it out.

1 Like

Thanks for the proxy_pass configuration, that was helpful :slight_smile:

1 Like