Running n8n Behind NGINX

Written By david

In this Post

This guide is only applicable if you install or have installed n8n using Docker.

About This Article

n8n, like any other software installed on a server and accessed via a browser, requires a web server to deliver the pages to the browser. In the case of n8n, it uses software called Caddy.

If you only use your current server for n8n and no other application, you can happily leave this as it is and everything will work perfectly.

You may run into some issues if you want to install other applications on your server alongside n8n, and they need a web server. That’s because Caddy may not be compatible with your new application or must be configured to work with it.

Caddy is a great web server, so if you can configure Caddy to work with your new application, that might be the way to go.

Many applications that you may use will recommend you either use Apache or NGINX – these are 2 of the more popular web servers and, if it is the case you need to use one of these, NGINX tends to be the higher performing and essentially easier to configure (just a personal opinion).

This article looks at configuring n8n to work with NGINX rather than Caddy.

Install NGINX

The first stage of this process is to install NGINX. If you have this installed already, you can skip to the next section.

Firstly, update your server:

sudo apt update

Then install NGINX:

sudo apt install nginx -y

Create a Configuration File

Next, we need to create a configuration file for NGINX and n8n.

Create the configuration file:

sudo nano /etc/nginx/sites-available/n8n

Then add the following to the configuration file. Replace <your-domain> with the domain n8n is currently installed at without http:// or https://. If you used any other port that 5678 to install n8n, then change 5678 to the correct port too

Save and exit the file (ctrl + x, Y to save the modified buffer and Enter to save the file)

We then need to create a symlink to the new file:

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/

Then test NGINX to make sure everything is OK:

sudo nginx -t

Configure n8n to Work With NGINX

To make n8n work with NGINX, we need to make some changes to the docker-compose.yml file. If you followed our guide on how to install n8n with Docker, these commands will work for you. If you installed with Docker but followed another guide, you will need to find where your docker-compose.yml file is and move to that directory:

Move to the directory where the docker compose file sits:

cd /home/n8n-docker-caddy

Then open the docker-compose file to edit it:

nano docker-compose.yml

We need to remove the entire caddy block from this file and the reference to Caddy Data. Delete the parts you see in the red boxes in the image below:

OK, now we need to stop and remove Caddy.

Run this command to identify the Caddy container ID:

docker ps --filter "publish=80"

This will return something like the image below. Make a note of the container ID. The one in the example is in the red square. You need to capture whatever yours is:

Then, run these commands to stop and remove the container Replace <caddy-container-id> with the container ID you copied:

docker stop <caddy-container-id>
docker rm <caddy-container-id>

Now, we need to restart NGINX in order for it to bind to the correct ports. Run:

systemctl restart nginx

Finally, stop and restart Docker:

docker-compose down && docker-compose up -d

Install an SSL for Your Domain

We then move onto obtaining an SSL for your domain to work inside of NGINX. This will fail if you haven’t pointed the domain to your IP address.

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Then request the certificate. Replace <your-domain> with your full domain name without http:// or https://:

sudo certbot --nginx -d <your-domain>

Follow the prompts to install the certificate.

Now, access n8n from the browser and you should see it as you did previously. If there are any errors or it won’t load, revisit each step to be sure everythinh was completed.

Wrapping Up

That should be all you need to do to run n8n behing NGINX. A few things to test:

Run the following command to stop NGINX:

systemctl stop nginx

Then try and access n8n in the browser. If you can no longer see your n8n instance, it means it is now being served via NGINX.

Run the following to restart:

systemctl start nginx

Check one of your existing workflows or create new one and send data to the test url to make sure everything is receiving OK.

If that’s all OK, then you are good to go.

Join our free community and discuss this article and video. You can also ask for help with your own use case.

Some of our posts contain referral links and affiliate links where we receive a small payment for a recommendation. In many cases, the recommendations we make will also mean that you receive an offer or a credit too.

We only provide links to relevant content, for example where we have mentioned a service in the a workflow. We never provide any personal data to the sites we link too and we do not use any of this data for marketing purposes.

Where we have made a recommendation, this will be clearly mentioned in the relevant post.

Receive the latest articles in your inbox