n8n is an open-source workflow automation tool. It connects apps and APIs and runs tasks on a schedule or when a webhook fires, mostly without writing code.
This guide is for people running n8n on their own VPS. It covers installing n8n with Docker Compose, putting it behind Nginx with an SSL certificate, and the settings, backups and security steps that keep it running reliably.
Why run n8n in Docker
Compared with installing n8n directly on the server:
- Isolation: n8n and its Node.js version live in their own container, separate from the rest of the system.
- Updates: you update n8n by pulling a new image and recreating the container.
- Consistency: the same image runs on your laptop and on the server.
- Portability: moving to another server means copying the Compose file and the data volume.
- Resource control: you can cap how much CPU and memory the container uses.
- Fewer conflicts: nothing n8n needs can clash with other software on the VPS.
Prerequisites
You'll need:
- VPS Access: Root or sudo access to your VPS
- Docker Installed: Docker and Docker Compose installed on your VPS (Step 1 covers this)
- Domain Name: A domain pointing to your VPS IP (optional but recommended)
- SSL Certificate: For HTTPS access (Let's Encrypt, set up in Step 4)
- Minimum Resources: 2GB RAM, 2 CPU cores, 20GB storage
- Firewall: Ports 80 and 443 open. Open 5678 only while testing without the proxy.
Step 1: Install Docker and Docker Compose
Skip this step if Docker and Docker Compose are already installed on the VPS.
1 Install Docker
These commands are for Ubuntu. On Debian, replace ubuntu with debian in the two download.docker.com URLs.
# Update package index
sudo apt update
# Install prerequisites
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
# Verify installation
sudo docker --version
2 Install Docker Compose
This installs the standalone docker-compose command used in the rest of this guide:
# Download Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Make it executable
sudo chmod +x /usr/local/bin/docker-compose
# Verify installation
docker-compose --version
3 Add your user to the docker group (optional)
This lets you run Docker commands without sudo:
# Add user to docker group
sudo usermod -aG docker $USER
# Log out and log back in for changes to take effect
# Or run: newgrp docker
Step 2: Create the Docker Compose configuration
1 Create the n8n directory
# Create directory for n8n
mkdir -p ~/n8n
cd ~/n8n
2 Create docker-compose.yml
Save the following as docker-compose.yml. The restart policy brings the container back after a crash or reboot, and the health check lets Docker report whether n8n is actually responding:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_ENCRYPTION_KEY=your_long_random_key_here
- N8N_HOST=yourdomain.com
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://yourdomain.com/
- GENERIC_TIMEZONE=UTC
- TZ=UTC
volumes:
- n8n_data:/home/node/.n8n
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:5678/healthz || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- n8n-network
volumes:
n8n_data:
driver: local
networks:
n8n-network:
driver: bridge
Before you start the container: replace yourdomain.com with your actual domain name, and your_long_random_key_here with a random key. You can make one with openssl rand -hex 32. n8n uses this key to encrypt the credentials you save, so keep a copy somewhere safe: if it is lost, saved credentials can't be read after a rebuild.
The first time you open n8n in the browser, it asks you to create the owner account. That account's email and password are your login from then on. (Older guides use N8N_BASIC_AUTH_USER and N8N_BASIC_AUTH_PASSWORD. Those settings were removed in n8n 1.0 and do nothing now.)
Step 3: Move settings into an environment file
A separate file keeps the encryption key out of the Compose file.
1 Create the .env file
Create a .env file in the same directory:
# Create .env file
nano .env
Add the following content:
N8N_ENCRYPTION_KEY=your_long_random_key_here
N8N_HOST=yourdomain.com
N8N_PROTOCOL=https
NODE_ENV=production
WEBHOOK_URL=https://yourdomain.com/
GENERIC_TIMEZONE=UTC
TZ=UTC
2 Point docker-compose.yml at the .env file
Replace the environment block with env_file:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
env_file:
- .env
volumes:
- n8n_data:/home/node/.n8n
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:5678/healthz || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- n8n-network
volumes:
n8n_data:
driver: local
networks:
n8n-network:
driver: bridge
Step 4: Set up a reverse proxy with SSL (Nginx)
Nginx handles HTTPS and passes requests to n8n on port 5678.
1 Install Nginx and Certbot
# Install Nginx
sudo apt install -y nginx
# Install Certbot for SSL certificates
sudo apt install -y certbot python3-certbot-nginx
# Start and enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
2 Create the Nginx configuration
Create a server block for n8n:
# Create Nginx configuration
sudo nano /etc/nginx/sites-available/n8n
Add the following configuration. The Upgrade and Connection headers are needed because the n8n editor uses a WebSocket connection:
server {
listen 80;
server_name 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_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_cache_bypass $http_upgrade;
}
}
3 Enable the site and get an SSL certificate
Your domain's DNS must already point at the VPS, or Certbot can't issue the certificate.
# Enable the site
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
# Test Nginx configuration
sudo nginx -t
# Reload Nginx
sudo systemctl reload nginx
# Obtain SSL certificate
sudo certbot --nginx -d yourdomain.com
# Certbot will automatically configure SSL and update your Nginx config
Step 5: Start the n8n container
From the n8n directory, start the container in the background and check that it came up:
# Navigate to n8n directory
cd ~/n8n
# Start n8n in detached mode
docker-compose up -d
# Check container status
docker-compose ps
# View logs
docker-compose logs -f n8n
n8n is now running.
Open https://yourdomain.com, or http://your-vps-ip:5678 if you haven't set up the proxy yet.
Keeping n8n stable
1. Use health checks
The health check calls n8n's /healthz endpoint every 30 seconds and marks the container unhealthy after three failures, which you'll see in docker-compose ps. Docker doesn't restart an unhealthy container by itself, so use it alongside your monitoring and the restart policy below.
2. Set a restart policy
restart: unless-stopped restarts the container if n8n crashes and starts it again after the server reboots, unless you stopped it yourself.
3. Set resource limits
Stop a runaway workflow from taking all the server's memory and CPU. Add this under the n8n service in docker-compose.yml:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
4. Back up regularly
Back up the n8n_data volume on a schedule. The script in the next section does this.
5. Check the logs
Look through the logs for errors now and then: docker-compose logs n8n
6. Keep Docker and n8n updated
Update Docker with your normal system updates, and update n8n with: docker-compose pull && docker-compose up -d. The image tag is latest, so read the n8n release notes before updating, as major versions can include breaking changes.
Set up automated backups
This script archives the n8n data volume to /root/n8n/backups and deletes archives older than seven days. The paths assume you're working as root; change them if you're not.
Create the backup script
# Create backup script
nano ~/n8n/backup.sh
Add the following content. Docker Compose prefixes volume names with the project directory, so with ~/n8n the volume is n8n_n8n_data. Run docker volume ls to check yours.
#!/bin/bash
BACKUP_DIR="/root/n8n/backups"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/n8n_backup_$DATE.tar.gz"
# Create backup directory if it doesn't exist
mkdir -p $BACKUP_DIR
# Create backup
docker run --rm -v n8n_n8n_data:/data -v $BACKUP_DIR:/backup ubuntu tar czf /backup/n8n_backup_$DATE.tar.gz /data
# Keep only last 7 days of backups
find $BACKUP_DIR -name "n8n_backup_*.tar.gz" -mtime +7 -delete
echo "Backup completed: $BACKUP_FILE"
Make the script executable and schedule it with cron to run daily at 2am:
# Make script executable
chmod +x ~/n8n/backup.sh
# Add to crontab (daily backup at 2 AM)
crontab -e
# Add this line:
0 2 * * * /root/n8n/backup.sh >> /root/n8n/backup.log 2>&1
Securing n8n
1. Use a strong password
Use a long, random password for the owner account, and turn on two-factor authentication in your n8n personal settings.
2. Use HTTPS only
Don't expose n8n over plain HTTP in production.
3. Close port 5678
Once Nginx is working, block public access to port 5678 so n8n is only reachable through the proxy on ports 80 and 443. Docker adds its own iptables rules, so a ufw rule alone may not block a published port. Changing the port mapping to 127.0.0.1:5678:5678 keeps it local to the server.
4. Keep software updated
Update n8n and Docker to pick up security fixes.
5. Restrict access by IP
If only your office or VPN needs the editor, use firewall rules to allow just those IP addresses.
6. Keep credentials in n8n
Store API keys and passwords in n8n's credentials system, not in workflow code.
Common issues and troubleshooting
Issue: Container won't start
Solution:
- Check logs:
docker-compose logs n8n - Check Docker is running:
sudo systemctl status docker - Check for port conflicts:
sudo netstat -tulpn | grep 5678 - Check the .env file for typos: one KEY=value per line, with no spaces around the equals sign
Issue: Can't access n8n via domain
Solution:
- Check DNS is pointing to your VPS IP
- Check Nginx configuration:
sudo nginx -t - Check the SSL certificate is valid:
sudo certbot certificates - Check the firewall allows ports 80 and 443
Issue: High memory usage
Solution:
- Add resource limits to docker-compose.yml
- Monitor with:
docker stats n8n - Consider upgrading VPS resources
- Split large workflows or process data in smaller batches
Issue: Workflows not executing
Solution:
- Check container logs for errors
- Check webhook URLs are correct
- Check the firewall allows incoming connections
- Check NODE_ENV is set to production
n8n VPS hosting at HosterOcean
What's included
If you'd rather skip the installation, our n8n VPS comes with n8n already installed, so you can log in and start building workflows. You also get full root access, so you can change the configuration, add other services or follow any part of this guide yourself.
Locations and support
VPS servers are available in New York, Chicago and London. Live chat is open from 9am to 8pm CT every day, and you can open a support ticket at any hour. If you're moving an existing n8n instance, ask our team about migrating it.
See n8n VPS plansSummary of the setup
Docker Compose keeps n8n isolated and easy to update. Put it behind Nginx with a Let's Encrypt certificate and close port 5678 to the public. Use the restart policy, health check and resource limits, and back up the data volume daily so you can recover your workflows if the server fails.
Tags:
Related articles
n8n VPS Hosting - Pre-Installed Workflow Automation
VPS plans with n8n already installed, so you can start building workflows without setting it up yourself.
Read More →How to Install WordPress on cPanel
Step-by-step instructions for installing WordPress on cPanel, with Softaculous or by hand.
Read More →