Back to blog
Jun 08, 2025
4 min read

Install n8n with Docker Compose and Nginx on Ubuntu VPS

Deploy n8n workflow automation on Ubuntu VPS with Docker Compose and Nginx. Includes SSL setup, authentication, and production best practices.

Introduction to Self-Hosting n8n

Automation is king in 2025 — and n8n is one of the most powerful open-source workflow automation tools you can self-host to supercharge your workflows. Whether you’re automating data pipelines, integrating APIs, or orchestrating business logic, setting up n8n on a reliable Ubuntu VPS with Docker Compose and Nginx (plus HTTPS via Let’s Encrypt) is the professional-grade route.

Why self-host n8n?

  • Full data control and privacy
  • No monthly subscription costs
  • Unlimited workflow executions
  • Custom integrations and modifications
  • Enterprise-grade security on your own infrastructure

In this guide, you’ll learn exactly how to:

  • Deploy n8n using Docker Compose
  • Secure it with Nginx reverse proxy
  • Install Let’s Encrypt SSL certificates
  • Run everything smoothly on Ubuntu VPS (22.04 or newer)

Let’s get into it. 🛠️


🚀 Prerequisites

Before we jump into commands, let’s make sure you’ve got the basics ready:

  • A Ubuntu VPS (we’re using Ubuntu 22.04 LTS)
  • Root or sudo privileges
  • Docker & Docker Compose installed
  • A registered domain pointing to your VPS IP (e.g., n8n.yourdomain.com)

Step 1: Create a Directory Structure

Let’s keep things organized:

mkdir -p ~/n8n/docker ~/n8n/nginx
cd ~/n8n

Step 2: Docker Compose for n8n

Inside ~/n8n/docker, create a docker-compose.yml file:

version: "3"

services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=yourStrongPassword
      - WEBHOOK_TUNNEL_URL=https://n8n.yourdomain.com
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Replace yourStrongPassword and n8n.yourdomain.com with your actual secure password and domain name.

Start it up:

cd ~/n8n/docker
docker-compose up -d

n8n is now running on port 5678, but it’s not secured yet. Let’s fix that next.


Step 3: Install Nginx and Certbot

sudo apt install -y nginx certbot python3-certbot-nginx

Now configure Nginx.


Step 4: Configure Nginx for Reverse Proxy

Create a config file in /etc/nginx/sites-available/n8n:

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

Enable the site:

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 5: Secure with Let’s Encrypt

Time for SSL:

sudo certbot --nginx -d n8n.yourdomain.com

Certbot will auto-configure SSL in your nginx block. After it’s done, you can test HTTPS access.

Verify your SSL cert renewal cron job exists:

sudo systemctl list-timers

Step 6: Auto-Restart with System Reboots

Add a restart policy in your Docker Compose file if not already present:

restart: always

Or add this to crontab:

@reboot cd /home/youruser/n8n/docker && docker-compose up -d

Use crontab -e to set this up under your user account.


Step 7: Access Your n8n Dashboard

Visit https://n8n.yourdomain.com and log in using your Basic Auth credentials.

Congratulations — you’ve got n8n deployed with Docker Compose, reverse proxied with Nginx, and secured with SSL on a rock-solid Ubuntu VPS. 🔒


Enable OAuth or JWT Auth (for production)

You can go beyond Basic Auth by integrating OAuth with services like GitHub or Google. This is ideal for team environments or shared deployments. See n8n auth docs for more details.

Backups

You should back up the n8n_data volume regularly. Use something like:

docker run --rm -v n8n_data:/data -v $(pwd):/backup alpine tar czf /backup/n8n_backup_$(date +%F).tar.gz /data

Why this setup is Better

  • Docker Compose keeps everything self-contained
  • Nginx ensures SSL, clean URLs, and faster response time
  • Let’s Encrypt makes SSL free and automated
  • Easy to migrate, replicate, or destroy and rebuild

It’s the perfect combo for small business automation, personal projects, or even production-grade SaaS workflows. And if you’re doing fitness automation or gamified habit tracking (shoutout to Workout Quest users automating their Google Sheets logs or Notion dashboards), this is your golden path.


🧾 References