Číst česky →

How to install n8n on a VPS with Docker Compose

6 min read Hukot net Linux Basics VPS AI

Contents Prerequisites Installation First login Connecting your own model in Ollama Backups Updates Why choose our VPS? Want automation without limits?

n8n is an automation tool where you connect applications and services into workflows by dragging blocks: for example, a new order creates an invoice, sends a Slack message and saves the data to a spreadsheet. On your own VPS you don't pay per execution and your data stays with you.

For maximum stability, we recommend installing it on a Hukot.net VPS: your server is ready within 60 seconds of ordering and your data stays in a data centre in the Czech Republic.

Prerequisites #

  • A VPS with Ubuntu 22.04 / 24.04 / 26.04 LTS or Debian 12 / 13 and SSH access with sudo rights.
  • At least 4 GB of RAM (the VPS-L04G tariff). When your workflows grow and memory runs short, you can switch to a higher tariff right in the administration and pay only the difference.
  • A domain or subdomain for n8n (for example n8n.example.com) whose A record points to the server's IP address. You can set the record by following How to edit DNS.
Before you startHow to install Docker and Docker Compose on Ubuntu and Debiann8n will run in Docker together with a PostgreSQL database. Install Docker and Docker Compose by following this tutorial.

n8n reachable from the internet must run over HTTPS. That's why this guide uses Nginx and a Let's Encrypt certificate.

Installation #

Configuration

  1. Create a directory for n8n:

    sudo mkdir -p /opt/n8n
    cd /opt/n8n
    
  2. Create a .env file with the domain, the time zone and randomly generated passwords:

    sudo tee .env > /dev/null <<EOF
    N8N_DOMAIN=<domain>
    GENERIC_TIMEZONE=Europe/Prague
    POSTGRES_PASSWORD=$(openssl rand -hex 24)
    N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
    EOF
    sudo chmod 600 .env
    

    Replace <domain> with the domain for n8n, for example n8n.example.com, and Europe/Prague with your time zone if it differs.

    n8n uses N8N_ENCRYPTION_KEY to encrypt the credentials for other services. Without it, you can't decrypt them after restoring from a backup. Back up the .env file in a safe place.

  3. Create the compose.yaml file:

    sudo nano compose.yaml
    
    services:
      postgres:
        image: postgres:17
        restart: unless-stopped
        environment:
          POSTGRES_USER: n8n
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
          POSTGRES_DB: n8n
        volumes:
          - postgres_data:/var/lib/postgresql/data
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
          interval: 10s
          timeout: 5s
          retries: 5
    
      n8n:
        image: n8nio/n8n
        restart: unless-stopped
        ports:
          - "127.0.0.1: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: ${POSTGRES_PASSWORD}
          N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
          N8N_HOST: ${N8N_DOMAIN}
          N8N_PORT: "5678"
          N8N_PROTOCOL: https
          N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/
          N8N_PROXY_HOPS: "1"
          N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
          NODE_ENV: production
          GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
          TZ: ${GENERIC_TIMEZONE}
        volumes:
          - n8n_data:/home/node/.n8n
        depends_on:
          postgres:
            condition: service_healthy
    
    volumes:
      postgres_data:
      n8n_data:
    

    The n8n port is published only on 127.0.0.1 because Docker bypasses the UFW firewall. The database publishes no port at all; n8n connects to it inside the Docker network.

Starting n8n

  1. Pull the images and start n8n in the background:

    sudo docker compose up -d
    
  2. Check that both containers are running. postgres should show the status healthy:

    sudo docker compose ps
    
  3. Look at the n8n log. After the first start it contains the message Editor is now accessible via:

    sudo docker compose logs -f n8n
    

    The first start takes a minute or two while n8n prepares the database. Stop following the log with Ctrl + C.

Nginx and HTTPS

In detailMultiple websites and applications on one VPS: Nginx as a reverse proxyThis tutorial covers Nginx as a reverse proxy, Let's Encrypt certificates and fixing common errors.
  1. Install Nginx and Certbot and allow HTTP and HTTPS in the firewall:

    sudo apt install -y nginx certbot python3-certbot-nginx
    sudo ufw allow 'Nginx Full'
    
  2. The n8n editor talks to the browser over WebSocket. Enable WebSocket support in /etc/nginx/conf.d/websocket.conf:

    sudo nano /etc/nginx/conf.d/websocket.conf
    
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    
  3. Create the file /etc/nginx/sites-available/n8n:

    sudo nano /etc/nginx/sites-available/n8n
    
    server {
        listen 80;
        listen [::]:80;
        server_name <domain>;
    
        client_max_body_size 50M;
    
        location / {
            proxy_pass http://127.0.0.1:5678;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $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-Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_buffering off;
            proxy_read_timeout 300s;
        }
    }
    

    Replace <domain> with the same domain as in the .env file.

  4. Enable the site and issue the certificate:

    sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx
    sudo certbot --nginx -d <domain>
    

First login #

  1. Open https://<domain> in your browser.
  2. Fill in the Set up owner account form. This account owns the instance and has all permissions, so do it right after the start.
  3. Invite other users in Settings → Users.

Connecting your own model in Ollama #

If you don't want to send data to OpenAI or another cloud AI, use your own language model in n8n. It runs on a Hukot.net GPU-VPS with 24 to 96 GB of VRAM and you don't pay for tokens.

Before you startOllama and Open WebUI on a GPU-VPS: your own AI chatInstall the graphics card driver and Ollama by following this tutorial (Open WebUI isn't needed), then run n8n on the same server.

Ollama listens only on 127.0.0.1, which the n8n container can't reach. It therefore has to listen on all addresses, and the firewall has to protect it from the internet.

This setup is safe only with the UFW firewall enabled. The Ollama API has no login, and without a firewall anyone on the internet could use your graphics card. Enable the firewall by following Setting up a firewall with UFW.

  1. Check that UFW is enabled. The output should say Status: active:

    sudo ufw status
    
  2. Allow access to Ollama only from Docker containers:

    sudo ufw allow from 172.16.0.0/12 to 172.17.0.1 port 11434 proto tcp
    

    172.17.0.1 is the server's address in the Docker network, which containers reach through host.docker.internal. The rule therefore doesn't open access on the server's public IP address.

  3. Make Ollama listen on all addresses:

    sudo systemctl edit ollama
    

    Paste into the opened file:

    [Service]
    Environment="OLLAMA_HOST=0.0.0.0:11434"
    

    Save the file and restart Ollama:

    sudo systemctl restart ollama
    
  4. In /opt/n8n/compose.yaml, add the host address to the n8n service, at the same level as ports:

        extra_hosts:
          - "host.docker.internal:host-gateway"
    

    Apply the change:

    cd /opt/n8n
    sudo docker compose up -d
    
  5. From your own computer, check that Ollama isn't reachable from outside. The command should fail or time out:

    curl -m 5 http://<server-ip>:11434
    

    Replace <server-ip> with the server's IP address.

  6. In n8n, create Ollama credentials and enter http://host.docker.internal:11434 as the Base URL. Then use the model in the Ollama Chat Model or AI Agent nodes.

Backups #

All n8n data is in the PostgreSQL database, and the key to the credentials is in the .env file. Back up the database to a file:

cd /opt/n8n
sudo docker compose exec -T postgres pg_dump -U n8n n8n | sudo tee /root/n8n-$(date +%F).sql > /dev/null

Store the backup and the .env file outside the server.

Updates #

n8n releases new versions every week. Update it by pulling the new image:

cd /opt/n8n
sudo docker compose pull
sudo docker compose up -d

Before a bigger update, create a snapshot in the Hukot.net VPS administration. If anything breaks after the update, you can roll the server back to its previous state.

The postgres:17 image stays on major version 17 and receives only fixes. Moving to a new major PostgreSQL version requires converting the data, so don't change the version number without a backup.

Why choose our VPS? #

Unlike public clouds, we guarantee that your data stays in the Czech Republic, with top-class connectivity. Your n8n automations process customer data on a server in the Czech Republic and run non-stop with no limit on executions.

Want automation without limits? #

Order a VPS from Hukot.net and run your first n8n workflow today.

Choose a VPS configuration