How to Install n8n on VPS | Complete Guide 2025

n8n-blog

What is n8n and Why Use Docker for Installation?

n8n is a powerful open-source workflow automation tool that helps you connect different applications and automate repetitive tasks. Installing n8n using Docker on your VPS server provides the easiest, most reliable deployment method with isolated environments, simple updates, and consistent performance.

Key benefits of hosting n8n with Docker on VPS:

  • One-command installation and updates
  • Complete data control and privacy
  • No workflow execution limits
  • Isolated and secure environment
  • Easy backup and migration
  • Consistent performance across systems

Prerequisites

Before installing n8n with Docker on your VPS, ensure you have:

  • Linux VPS server (UnixHost Pro VPS recommended – reliable and affordable)
  • Ubuntu 20.04 or newer (or Debian/CentOS)
  • Minimum 2GB RAM (4GB+ recommended for production)
  • Root or sudo access
  • Domain name (optional, but recommended for SSL)

Step 1: Connect to Your VPS Server

First, connect to your VPS via SSH:

ssh root@your_server_ip

Replace your_server_ip with your actual VPS IP address.

Step 2: Update System Packages

Keep your system secure and up-to-date:

sudo apt update && sudo apt upgrade -y

Step 3: Install Docker and Docker Compose

Install Docker using the official script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Verify Docker installation:

docker --version

Install Docker Compose:

sudo apt install docker-compose -y

Verify Docker Compose:

docker-compose --version

Enable Docker to start on boot:

sudo systemctl enable docker
sudo systemctl start docker

Step 4: Create n8n Directory Structure

Create a dedicated directory for n8n data:

mkdir -p ~/.n8n
cd ~/.n8n

This directory will store your workflows, credentials, and database.

Step 5: Create Docker Compose Configuration

Create a docker-compose.yml file:

nano docker-compose.yml

Add the following configuration:

version: '3.8'

services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=your_secure_password_here
      - N8N_HOST=${N8N_HOST:-localhost}
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - WEBHOOK_URL=http://your_domain.com/
      - GENERIC_TIMEZONE=Europe/London
    volumes:
      - ./n8n_data:/home/node/.n8n
    networks:
      - n8n-network

networks:
  n8n-network:
    driver: bridge

Important: Replace your_secure_password_here with a strong password and update your_domain.com with your actual domain.

Save the file (Ctrl+O, Enter, Ctrl+X).

Step 6: Start n8n with Docker

Launch n8n using Docker Compose:

docker-compose up -d

Check if the container is running:

docker ps

View n8n logs:

docker logs n8n -f

By default, n8n runs on port 5678. Access it via: http://your_server_ip:5678

Step 7: Configure Nginx Reverse Proxy (Recommended)

Install Nginx:

sudo apt install nginx -y

Create Nginx configuration:

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

Add this configuration:

server {
    listen 80;
    server_name your_domain.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;
    }
}

Enable the site:

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

Step 8: Secure n8n with SSL Certificate

Install Certbot for free SSL:

sudo apt install certbot python3-certbot-nginx -y

Obtain SSL certificate:

sudo certbot --nginx -d your_domain.com

Update your docker-compose.yml to use HTTPS:

nano docker-compose.yml

Change the environment variables:

- N8N_PROTOCOL=https
- WEBHOOK_URL=https://your_domain.com/

Restart n8n:

docker-compose down
docker-compose up -d

Step 9: Configure Firewall

Allow necessary ports:

sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Step 10: Access Your n8n Installation

Visit your domain: https://your_domain.com

Log in with the credentials you set in docker-compose.yml and start creating workflows!

Step 11: Managing n8n with Docker

Stop n8n:

docker-compose stop

Start n8n:

docker-compose start

Restart n8n:

docker-compose restart

Update n8n to latest version:

docker-compose pull
docker-compose up -d

View logs:

docker logs n8n -f

Backup n8n data:

tar -czf n8n-backup-$(date +%Y%m%d).tar.gz ./n8n_data

Advanced Configuration: PostgreSQL Database

For better performance in production, use PostgreSQL instead of SQLite:

Create an updated docker-compose.yml:

version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: n8n-postgres
    restart: always
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=your_db_password
      - POSTGRES_DB=n8n
    volumes:
      - ./postgres_data:/var/lib/postgresql/data
    networks:
      - n8n-network
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U n8n']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=your_db_password
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=your_secure_password
      - N8N_HOST=${N8N_HOST:-localhost}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://your_domain.com/
      - GENERIC_TIMEZONE=Europe/London
    volumes:
      - ./n8n_data:/home/node/.n8n
    networks:
      - n8n-network
    depends_on:
      postgres:
        condition: service_healthy

networks:
  n8n-network:
    driver: bridge

Apply the configuration:

docker-compose down
docker-compose up -d

Performance Optimization Tips

Increase Docker container resources:

Add to your docker-compose.yml under the n8n service:

    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
        reservations:
          memory: 1G

Enable Docker logging limits:

    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

Use Docker volumes for better performance:

volumes:
  n8n_data:
  postgres_data:

Troubleshooting Common Issues

Container not starting:

docker logs n8n
docker-compose logs -f

Check container status:

docker ps -a

Reset n8n completely:

docker-compose down -v
docker-compose up -d

Database connection issues:

docker exec -it n8n-postgres psql -U n8n -d n8n

Permission issues:

sudo chown -R 1000:1000 ./n8n_data

Why Choose UnixHost Pro for n8n Docker Hosting?

When selecting a VPS provider for n8n Docker deployment, UnixHost Pro VPS offers:

  • High-performance SSD storage for Docker volumes
  • Optimized for containerized applications
  • Reliable uptime and fast network
  • Flexible resource scaling
  • Pre-configured Docker support
  • Competitive pricing
  • Expert technical support 24/7

Conclusion

Installing n8n with Docker on your VPS server provides the most efficient and maintainable workflow automation setup. With Docker, you get easy updates, simple backups, and isolated environments. Following this guide, you can have a production-ready n8n instance running in under 15 minutes.

Ready to automate your workflows with Docker? Get started with a reliable Linux VPS from UnixHost Pro today!


Keywords: n8n docker installation, docker compose n8n, VPS automation, workflow automation docker, n8n VPS setup, Linux VPS docker, n8n container, automation tools, self-hosted n8n, n8n docker tutorial, VPS hosting, docker deployment, containerized n8n