Back to Blog

Chatbot

n8n Self-Hosted on a Linux Server with SSL Enabled

2 min read

Updated

n8n Self-Hosted on a Linux Server with SSL Enabled

This guide provides step-by-step instructions on how to self-host n8n, a free and open-source workflow automation tool, on a Linux server using Docker, Nginx, and Certbot for SSL with a custom domain name.

Step 1: Installing Docker

Update the package index:

sudo apt update

Install Docker:

sudo apt install docker.io

Start Docker:

sudo systemctl start docker

Enable Docker to start at boot:

sudo systemctl enable docker


Step 2: Starting n8n in Docker

Run the following command to start n8n in Docker. Replace your-domain.com with your actual domain name:

If you are using a subdomain, it should look like this:

Explanation of the command:

  • Downloads and runs the n8n Docker image.
  • Exposes n8n on port 5678.
  • Sets environment variables for the n8n host and webhook tunnel URL.
  • Mounts the n8n data directory for persistent storage.

After executing the command, n8n will be accessible at your-domain.com:5678.


Step 3: Installing Nginx

Nginx is a reverse proxy that forwards requests to n8n and handles SSL termination.

Install Nginx:

sudo apt install nginx


Step 4: Configuring Nginx

Configure Nginx to reverse proxy the n8n web interface.

Create a new Nginx configuration file:

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

Paste the following configuration:

Replace your-domain.com with your actual domain name.

Enable the configuration:

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

Test the Nginx configuration and restart the service:

sudo nginx -t
sudo systemctl restart nginx


Step 5: Setting up SSL with Certbot

Certbot will obtain and install an SSL certificate from Let's Encrypt.

Install Certbot and the Nginx plugin:

sudo apt install certbot python3-certbot-nginx

Obtain an SSL certificate:

sudo certbot --nginx -d n8n.envisiontech.agency

Follow the on-screen instructions to complete the SSL setup. Once completed, n8n will be securely accessible over HTTPS at your-domain.com.

n8n self hosted RAG chatbot flow view

Important Notes

  • Ensure your domain's DNS A record points to your server's IP address.
  • Allow ports 80 (HTTP), 443 (HTTPS), and 5678 (n8n) in your server's firewall.
  • Nginx handles SSL termination, so it internally forwards requests to the n8n instance over HTTP.

Why Nginx and Certbot?

  • Nginx: Acts as a reverse proxy, forwarding client requests to n8n running on Docker. This setup enhances security, load balancing, and scalability.
  • Certbot: A tool from the Electronic Frontier Foundation (EFF) that automates obtaining and renewing SSL certificates from Let's Encrypt, a free and open Certificate Authority.

By using Nginx and Certbot, you ensure that your n8n instance is securely accessible over the internet with HTTPS.


Troubleshooting

  • If you encounter issues with Nginx, check the logs located at /var/log/nginx/error.log for more details.
  • For Docker-related issues, ensure the Docker service is running:

sudo systemctl status docker

White-label tech partner

Your agency has the clients. I have the tech layer.

You don't need to build a technical team before you can take on technical work. Whether you're an established agency or just getting started, I can provide the technical layer behind your delivery, from building the system to getting it into production.

PolarBuild case study
  • You only sell once

    We never compete for your end clients. One partnership conversation. You fulfil for every account in your base.

  • Free POC before big builds

    A three-day sales demo on the proven stack before any large software investment. You pitch to your prospects or existing clients. Implementation starts only when someone pays.

  • Geography replication

    UK dental becomes US dental with a new local partner and new integration targets. Same playbook, new market.