Knowledgebase

How to install n8n on a VPS (self-hosted automation with Docker)

n8n is an open-source workflow automation tool, similar to Zapier or Make, that you can host on your own server. Self-hosting gives you full control over your data and no per-task limits from a SaaS plan. This guide shows how to install n8n on a VPS with Docker, put it behind Nginx with a domain and free SSL, and keep it updated and backed up.

What you need: a VPS with root access (not shared hosting), a subdomain such as n8n.example.com pointing to the server IP, and Docker installed as explained in How to install Docker on a VPS (AlmaLinux).

Step 1: Point a subdomain to the server

Create an A record for n8n.example.com with the VPS IP in your DNS zone (see How to manage DNS records). Wait until it resolves before you request SSL.

Step 2: Run n8n with Docker

Create a volume for n8n data (workflows, credentials and settings) and start the container. Replace n8n.example.com with your subdomain:

docker volume create n8n_data
docker run -d --name n8n --restart unless-stopped \
  -p 127.0.0.1:5678:5678 \
  -e N8N_HOST=n8n.example.com \
  -e N8N_PROTOCOL=https \
  -e WEBHOOK_URL=https://n8n.example.com/ \
  -e GENERIC_TIMEZONE=Africa/Cairo \
  -e TZ=Africa/Cairo \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n
docker logs -f n8n

The port is published only on 127.0.0.1, so n8n is not exposed directly to the internet. Nginx will handle public traffic.

Step 3: Add the Nginx reverse proxy

  1. Install Nginx and allow it to connect to local apps:
sudo dnf install -y nginx
sudo setsebool -P httpd_can_network_connect 1
sudo nginx -t && sudo systemctl enable --now nginx
  1. Create /etc/nginx/conf.d/n8n.example.com.conf. The WebSocket headers are required, otherwise the editor shows connection errors:
server {
    listen 80;
    server_name n8n.example.com;

    location / {
        proxy_pass http://127.0.0.1:5678;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_buffering off;
        proxy_read_timeout 300s;
    }
}
  1. Reload Nginx (sudo systemctl reload nginx) and install SSL with Certbot as shown in How to install a free Let's Encrypt SSL with Certbot on a VPS.

Step 4: Create the owner account

Open https://n8n.example.com. The first time, n8n asks you to create the owner account. Use a strong password and do this immediately, because whoever opens the page first can create the owner.

Step 5: Back up and update

Back up the data volume regularly. This command creates a compressed archive in the current folder:

docker run --rm -v n8n_data:/data -v "$PWD":/backup alpine \
  tar czf /backup/n8n_data_$(date +%F).tar.gz -C /data .

Also export important workflows from the n8n interface from time to time.

To update, take a backup first, then pull the new image and recreate the container. Your data stays in the volume:

docker pull docker.n8n.io/n8nio/n8n
docker stop n8n && docker rm n8n
# run the same "docker run" command from Step 2 again

Tips

  • n8n can use a lot of memory with large workflows. If the VPS has little RAM, add swap (How to create swap space on Linux) and watch usage with docker stats.
  • For heavier use, n8n supports PostgreSQL instead of the default SQLite database. Check the official n8n documentation for the environment variables.
  • Keep the server itself secure: SSH keys, a firewall and updates (How to secure your Linux server).

Common problems

  • "Connection lost" in the editor: the WebSocket headers are missing in the Nginx config.
  • Webhook URLs show localhost:5678: WEBHOOK_URL is not set. Recreate the container with the correct variable.
  • Wrong times in scheduled workflows: set GENERIC_TIMEZONE to your time zone.
  • 502 Bad Gateway: check that the container is running with docker ps and read docker logs n8n.

Frequently asked questions

Is self-hosted n8n free?

The self-hosted Community Edition is free to use under n8n's license, and you pay only for your server. Some enterprise features need a paid n8n license; check n8n's site for current terms.

Can I install n8n on cPanel shared hosting?

Not in a reliable way. n8n needs a long-running process and root-level setup, so a VPS is the right choice.

Need help? Open a support ticket or message us on WhatsApp +20 127 113 3655.

  • n8n, automation, Docker, VPS, Nginx, self-hosted

Was this answer helpful?

0 Users Found This Useful