Automation tools save hours of copy-and-paste work: new form submissions land in a spreadsheet, invoices trigger a team notification, a nightly job pulls data from one service and pushes it to another. Hosted automation platforms are easy to start with, but per-task pricing can add up quickly once your workflows get busy.
n8n is a workflow automation tool with a visual editor and hundreds of built-in integrations, and its source is available so you can run it on your own server. This guide shows how to self-host n8n on a VPS using Docker Compose, put it behind Nginx with a free SSL certificate, and keep it updated and backed up.
A quick note on licensing
n8n is distributed under its own Sustainable Use License, which n8n describes as "fair-code." In general it allows you to self-host and use n8n for your own internal business purposes. If you plan to offer n8n to others as a commercial service, read the license terms carefully first.
What you need
- A VPS running Ubuntu 22.04 or 24.04. A small instance with 1 to 2 GB of RAM is fine for light personal use; heavier workflows need more
- Docker and the Docker Compose plugin installed (our guide to running Docker on a VPS covers this)
- A subdomain, such as
n8n.yourdomain.com, with an A record pointing to your VPS - Nginx installed for the reverse proxy
Why a reverse proxy matters
You could open port 5678 and use n8n over plain HTTP, but you shouldn't. Workflows often hold API keys and credentials for your other services, and webhooks from outside services generally expect HTTPS. The safest pattern is:
- n8n listens only on
127.0.0.1:5678, unreachable from the internet - Nginx accepts HTTPS traffic on port 443 and forwards it to n8n
Step 1: Create a project folder
mkdir -p ~/n8n && cd ~/n8n
Step 2: Write the Docker Compose file
Create docker-compose.yml:
services:
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.com/
- NODE_ENV=production
- GENERIC_TIMEZONE=America/New_York
- TZ=America/New_York
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
What the important settings do:
127.0.0.1:5678:5678publishes the port only on the local loopback interface, so only Nginx on the same server can reach it.N8N_HOSTandN8N_PROTOCOLtell n8n its public address so links in the editor are correct.WEBHOOK_URLis the base address n8n shows for webhook nodes. Without it, webhook URLs can point tolocalhost, and outside services won't be able to reach them.GENERIC_TIMEZONEcontrols the time zone for schedule triggers, so a workflow set for 9 AM runs at 9 AM your time. Change it to your own zone.n8n_datavolume stores your workflows, credentials and the encryption key n8n uses to protect those credentials. Losing this volume means losing everything, so it's the most important thing to back up.
By default n8n uses a built-in SQLite database inside that volume, which works well for personal and small-team use. For larger setups, n8n also supports PostgreSQL; see the official docs for the extra environment variables.
Step 3: Start n8n
docker compose up -d
docker compose logs -f
Watch the logs until n8n reports that the editor is accessible, then press Ctrl+C to stop following. The container keeps running in the background.
Step 4: Configure Nginx
Create /etc/nginx/sites-available/n8n:
server {
listen 80;
server_name n8n.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
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;
proxy_buffering off;
proxy_read_timeout 3600s;
}
}
The Upgrade and Connection headers matter: the n8n editor uses a WebSocket connection to push live updates, and without them the editor may show connection errors. proxy_buffering off helps live execution data show up promptly.
Enable the site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 5: Add a free SSL certificate
With DNS pointing at your server, use Certbot's Nginx plugin to get a Let's Encrypt certificate and update the config automatically:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d n8n.yourdomain.com
Certbot sets up automatic renewal for you. For more detail, see our Let's Encrypt and Certbot guide.
Step 6: Create the owner account
Visit https://n8n.yourdomain.com. On first load, n8n asks you to set up an owner account with an email and password. Do this immediately after the site goes live, since the setup screen is open to whoever gets there first.
Once you're in, you can build your first workflow: add a trigger (a schedule, a webhook or an app event), connect action nodes, and test each step with real data in the editor.
Updating n8n
n8n releases updates often. To move to the newest image:
cd ~/n8n
docker compose pull
docker compose up -d
Your workflows and credentials survive because they live in the n8n_data volume, not inside the container. Before major version upgrades, skim n8n's release notes for breaking changes, and take a backup first. If you prefer predictable upgrades, pin a specific version tag in the image: line instead of always pulling the latest.
Backing up your workflows
There are two good layers of protection:
- Volume backups. Stop the container briefly and archive the volume:
docker compose stop
docker run --rm -v n8n_n8n_data:/data -v "$PWD":/backup alpine tar czf /backup/n8n-backup.tar.gz -C /data .
docker compose start
Docker Compose prefixes volume names with the project folder name, which is why the volume is called n8n_n8n_data here. Confirm the exact name with docker volume ls.
- Workflow exports. The n8n CLI inside the container can export workflows as JSON:
docker compose exec n8n n8n export:workflow --all --output=/home/node/.n8n/workflows-backup.json
Copy backups off the VPS regularly. If you also back up credentials, keep the encryption key safe, because exported credentials can't be decrypted without it.
Security checklist
- Keep port 5678 bound to
127.0.0.1so n8n is reachable only through Nginx. - Use a strong owner password and enable two-factor authentication in your n8n user settings.
- Protect webhook workflows that do anything sensitive with header authentication or another check, since webhook URLs are reachable by anyone who knows them.
- Keep Docker, Nginx and Ubuntu updated.
Wrapping up
Self-hosting n8n on a VPS gives you a capable automation platform without per-execution billing, on a server you control. The setup is a single Docker Compose file, an Nginx reverse proxy and a free SSL certificate. Get the WEBHOOK_URL and time zone right, back up the data volume, and you'll have reliable automations running around the clock. If you're looking for a VPS to run it on, you can compare plans at Host Whimsy.