Login

How to Set Up and Secure Production-Ready n8n on Ubuntu 24.04 with Nginx and Let’s Encrypt.

This guide explains how to install, set up, and secure a production-ready self-hosted n8n instance on Ubuntu 24.04. It covers the complete process, including n8n installation, Nginx reverse proxy configuration, and SSL setup using Let’s Encrypt. By following this guide, you will enable secure HTTPS access and ensure reliable performance for production environments. This setup is ideal for users who require full control, security, and scalability for their automation workflows.

Supported VPS plans:

Prerequisites

  • Active VPS or Dedicated server from Host.co.in.
  • Ubuntu 20.04 or 22.04.
  • Root or sudo access.
  • Node.js v20 or later.
  • npm installed.

Step 1: Install System Updates.

apt update && apt upgrade -y

Step 2: Install Node.js and npm.

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
apt install nodejs -y

Verify installed version with commands below.

node -v
npm -v

Step 3: Install n8n globally

npm install -g n8n

Verify installation:

n8n --version

Step 4: Start n8n

n8n start

Step 5: (Optional) Run n8n as a Background Service.

npm install -g pm2

Start n8n with PM2:

pm2 start n8n
pm2 save
pm2 startup

Step 6: Set up Nginx to act as the reverse proxy that forwards all external domain traffic to your local n8n service.

apt install nginx -y

Verify Nginx:

systemctl status nginx

Step 7: Configure Nginx for n8n.

nano /etc/nginx/sites-available/n8n

Add the following configuration (replace n8n.yourdomain.com):

server {
    listen 80;
    server_name n8n.yourdomain.com;
    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        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;
    }
}

Enable the configuration:

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

Test and reload Nginx:

nginx -t
systemctl reload nginx

Step 8: Install Certbot (Let’s Encrypt SSL)

apt install certbot python3-certbot-nginx -y

Step 9: Obtain SSL Certificate

certbot --nginx -d n8n.yourdomain.com

Conclusion

Nginx and Let’s Encrypt SSL have been successfully set up for your self-hosted n8n on Ubuntu 24.04. This ensures secure, encrypted communication over HTTPS. The configuration is suitable and recommended for production environments.

Tausif Shaikh

How to Set Up and Secure Production-Ready n8n on Ubuntu 24.04 with Nginx and Let’s Encrypt.
Table of Contents
    ×