
How to Install n8n as a Service: Local Docker, VPS with Nginx, and Coolify (Beginner Developer Guide)
A deep, step-by-step guide to running n8n as a reliable service locally with Docker, on a VPS with Docker + manual Nginx reverse proxy, and deploying via Coolify—plus requirements, examples, and official documentation links.
n8n is easiest to try in minutes, but it’s also the kind of tool you quickly want to run as a service: stable restarts, persistent data, a real domain, HTTPS, and predictable upgrades. This guide walks you through three common setups that cover most developer needs:
- Local: run n8n with Docker (best for development and learning).
- VPS: run n8n with Docker behind manual Nginx + HTTPS (best for production-ish self-hosting).
- Coolify: deploy n8n using a PaaS-style workflow (best when you want simpler ops and repeatable deployments).
Where possible, I’ll link to official documentation so you can verify details and keep up with changes.
The configurations below are reference examples, not a deployment tested on your server. The VPS commands use a Linux shell; on Windows, use WSL for the multiline Bash commands or run the Compose commands from PowerShell. Before exposing an instance, choose a supported n8n release, read its upgrade notes, and provision the owner account. Self-hosting also makes you responsible for patching, credentials, backups, and recovery.
Version note: from n8n 2.35.0, use N8N_WEBHOOK_URL. Earlier releases use WEBHOOK_URL; the old name remains a deprecated alias in newer releases. Check the endpoint variables for your installed version. Examples below target releases with the new variable.
Before you start: what “as a service” means for n8n
Running n8n “as a service” typically implies:
- It restarts automatically if it crashes or your server reboots.
- Data persists across container rebuilds (volumes for the database and config).
- It’s reachable at a stable URL (domain, or at least a stable port).
- If exposed to the internet, it uses HTTPS, and you configure the public editor/webhook URLs and reverse-proxy headers so callbacks work correctly.
- You have a plan for upgrades, backups, and security.
Official docs you’ll likely reference throughout:
- n8n Docs (main): https://docs.n8n.io/
- n8n Docker docs: https://docs.n8n.io/hosting/installation/docker/
- n8n environment variables: https://docs.n8n.io/hosting/configuration/environment-variables/
- n8n security / user management (varies by version): https://docs.n8n.io/
- Docker docs: https://docs.docker.com/
- Docker Compose docs: https://docs.docker.com/compose/
- Nginx docs: https://nginx.org/en/docs/
- Certbot (Let’s Encrypt) docs: https://certbot.eff.org/
- Coolify docs: https://coolify.io/docs
Note: n8n docs evolve. If a setting looks different in your installed version, always trust the official n8n environment variable reference first.
Requirements (don’t skip this)
Local (Docker)
- Docker Engine installed (Docker Desktop on macOS/Windows, Docker Engine on Linux)
- Docker Compose support
- Newer Docker includes
docker composeas a plugin: https://docs.docker.com/compose/
- Newer Docker includes
VPS (Docker + Nginx)
- A VPS with a supported Linux distro (commonly Ubuntu/Debian)
- SSH access + a sudo-capable user
- A domain name you control, with DNS A/AAAA records pointing to your VPS
- Open ports:
80/tcp(for HTTP and Let’s Encrypt challenges)443/tcp(for HTTPS)
- Docker Engine installed on the VPS:
- A host and provider firewall allowing your actual SSH port and 80/443. Docker-published ports can bypass UFW rules; Docker documents this interaction. Keep the app on loopback and do not publish Postgres.
Coolify
- A server where Coolify is installed (or a hosted Coolify instance)
- Ability to deploy Docker-based apps from a repository or template
- Domain and DNS records, if you want HTTPS and webhooks from the public internet
- Coolify documentation for installation and reverse proxy/SSL handling:
Architecture overview (so the steps make sense)
If DNS, TLS, and reverse proxies are unfamiliar, the Internet infrastructure walkthrough follows a browser request through the network and web stack before you configure your own service.
There are two popular patterns:
- n8n + SQLite (simple, fine for local/dev; can work for small setups)
- n8n + Postgres (recommended for serious self-hosting, better concurrency and durability)
On a VPS, you’ll usually run:
n8ncontainerpostgrescontainer (recommended)nginxon the host (or in a container) as a reverse proxy- TLS via Let’s Encrypt (Certbot) or via your platform (Coolify can manage this)
1) Install n8n locally with Docker (beginner-friendly)
If you’re learning n8n or building workflows locally, this is the fastest and safest setup. You can choose between a quick single-container run or a more “service-like” docker compose with persistent storage.
Option A: Quick run (good for first launch)
Official Docker guidance: https://docs.n8n.io/hosting/installation/docker/
A typical quick run looks like:
docker run -it --rm \
-p 127.0.0.1:5678:5678 \
-v n8n_data:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
-p 127.0.0.1:5678:5678exposes n8n on the host’s loopback address. Omitting the IP publishes on all host interfaces by default; see Docker port publishing.-v n8n_data:/home/node/.n8npersists n8n config and data in a Docker volume--rmremoves the container when it exits (your data remains in the volume)
This is great to verify Docker works and n8n boots, but for “run it like a service,” Compose is cleaner.
Option B: Local docker compose (recommended)
Create a folder, for example:
mkdir n8n-local && cd n8n-local
Create a compose.yml:
services:
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION:?Set N8N_VERSION in .env}
ports:
- "127.0.0.1:5678:5678"
volumes:
- n8n_data:/home/node/.n8n
environment:
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- TZ=UTC
- GENERIC_TIMEZONE=UTC
# If you use webhooks from outside localhost, you'll need a public URL.
# For local testing with external callbacks, consider ngrok or a reverse tunnel.
restart: unless-stopped
volumes:
n8n_data:
Start it:
First create a .env containing N8N_VERSION=<chosen-stable-version> (replace the placeholder with an actual image tag from the n8n releases). The untagged quick-run image is convenient for a disposable trial; pin the version when you depend on the instance. Use a currently maintained Docker Engine: versions before 28 have a documented caveat for loopback publishing on the same local network.
docker compose up -d
docker compose logs -f
Open:
Complete the owner signup promptly. n8n uses its own user management; old N8N_BASIC_AUTH_* settings are not a replacement for login in modern n8n. A local HTTP instance is for development. Keep secure cookies enabled on public HTTPS deployments rather than disabling them to work around a proxy error.
Stop:
docker compose down
Local webhooks (important beginner gotcha)
If you use nodes that require incoming webhooks (Stripe, GitHub, etc.), localhost usually won’t work from the internet. Typical solutions:
- Use an HTTPS tunnel like ngrok or Cloudflare Tunnel
- Or deploy on a VPS / Coolify (next sections)
n8n has a webhook base URL setting to match your tunnel’s public endpoint (see the version note above). A tunnel makes the instance internet reachable; protect the editor and authenticate incoming webhook requests as required by the provider:
2) Install n8n on a VPS with Docker + manual Nginx (production-style)
This is the “classic” self-hosting setup: Docker for app + database, Nginx as reverse proxy, Let’s Encrypt for TLS.
Step 1: Prepare your VPS
1.1 DNS
Create a DNS record:
Arecord:n8n.example.com→ your VPS IPv4- Publish only the
Arecord for the IPv4-only Nginx example below. AddAAAAonly after configuring and testing IPv6 listeners, firewall access, and HTTPS; a broken IPv6 route can break clients and certificate validation even when IPv4 works.
Wait for propagation.
1.2 Install Docker on the VPS
Use the official Docker Engine install docs for your distro:
Verify:
docker --version
docker compose version
1.3 Open firewall ports
If using UFW (Ubuntu):
Keep an existing SSH session open and allow your actual SSH port before enabling the firewall; OpenSSH assumes the standard service profile.
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status
Step 2: Create a Docker Compose stack (n8n + Postgres)
n8n’s Docker documentation includes examples and notes about persistence:
Create a directory:
sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" /opt/n8n
cd /opt/n8n
This creates a private setup directory owned by your SSH user, so you can write compose.yml, .env, and backups there. sudo docker ... elevates the Docker command; a shell redirection such as > n8n_backup.sql still runs as your current user. Do not use a root-owned directory with ordinary-user writes unless you deliberately change the file-creation procedure. Docker access itself is highly privileged; restrict who can administer this stack.
Create compose.yml (example with Postgres):
For a fresh instance, create a private .env with N8N_VERSION, POSTGRES_PASSWORD, and N8N_ENCRYPTION_KEY. Choose a supported release and generate two different high-entropy secrets, for example with openssl rand -hex 32 twice. Keep .env out of Git and restrict it with chmod 600 .env. For an existing instance, preserve its current encryption key instead of generating a replacement. For larger deployments, use a secret manager or n8n’s file-based settings. n8n’s encryption key must remain stable: losing it makes saved credentials unreadable, and changing it is not a simple password rotation.
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}
- POSTGRES_DB=n8n
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 10
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION:?Set N8N_VERSION}
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
# Database config (n8n supports Postgres; see n8n docs)
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY:?Set N8N_ENCRYPTION_KEY}
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
# Basic URL settings (match your public URL)
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
# This is commonly required so n8n generates correct external webhook URLs
- N8N_WEBHOOK_URL=https://n8n.example.com/
- N8N_EDITOR_BASE_URL=https://n8n.example.com/
# Optional: set timezone
- TZ=UTC
- GENERIC_TIMEZONE=UTC
# One proxy here: Nginx directly in front of n8n.
- N8N_PROXY_HOPS=1
ports:
# Bind only to localhost so it's not publicly exposed without Nginx
- "127.0.0.1:5678:5678"
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
postgres_data:
Why bind
127.0.0.1:5678:5678? So n8n is only reachable locally, and the only public entry is via Nginx on 80/443.
The health check makes Compose wait for Postgres readiness; a plain depends_on only orders container startup. See Compose startup order. This small example uses the database initialization user; for a hardened deployment use a separate application role as in n8n’s Postgres hosting example. Keep Postgres on its existing major version during routine updates; a major upgrade requires a database migration.
Start:
sudo docker compose up -d
sudo docker compose logs -f
At this point, n8n should be listening on 127.0.0.1:5678.
Test from the VPS:
curl -I http://127.0.0.1:5678
Step 3: Install and configure Nginx as reverse proxy
Install Nginx (Ubuntu/Debian):
sudo apt update
sudo apt install -y nginx
Create an Nginx site config:
sudo nano /etc/nginx/sites-available/n8n.conf
Example configuration (HTTP first; TLS comes next):
This HTTP block is only a bootstrap step for obtaining TLS. Restrict public access during setup and do not enter credentials over HTTP. Complete owner setup using a local SSH forward or through HTTPS before leaving the instance publicly reachable.
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-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_read_timeout 300s;
proxy_send_timeout 300s;
proxy_buffering off;
}
}
Enable it:
sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Check the HTTP route without signing in, then move to HTTPS. The n8n proxy guide requires forwarded host/protocol/client information and the correct number of proxy hops. The example assumes Nginx is the sole proxy; with a CDN in front, configure trusted client-IP handling and the actual hop count rather than trusting arbitrary incoming headers.
Step 4: Add HTTPS with Let’s Encrypt (Certbot)
Follow Certbot’s official instructions for Nginx:
On Ubuntu with snap (commonly recommended by Certbot):
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Request a certificate and auto-configure Nginx:
sudo certbot --nginx -d n8n.example.com
Certbot should:
- Obtain a certificate
- Modify the Nginx server block to redirect HTTP → HTTPS
- Add TLS configuration
Test renewal:
sudo certbot renew --dry-run
Step 5: Verify n8n URL settings (webhooks must match)
If webhook URLs point to http://127.0.0.1:5678 or http://localhost, check the effective configuration and proxy headers (and recreate the container after changes). A working test webhook also does not activate the production webhook: publish/activate the workflow according to your n8n version and use its production URL.
Key variables to review in the official doc:
N8N_HOST,N8N_PROTOCOL,N8N_EDITOR_BASE_URL, the webhook base URL variable for your version, andN8N_PROXY_HOPS- Environment variables reference: https://docs.n8n.io/hosting/configuration/environment-variables/
After editing compose.yml, restart:
cd /opt/n8n
sudo docker compose up -d
Step 6: Run it reliably (service behaviors)
You already set:
restart: unless-stopped
That’s the Docker-native restart policy. Ensure the Docker daemon is enabled at boot; unless-stopped also respects containers you explicitly stopped. After a reboot, verify both the application and a real webhook execution rather than assuming the restart policy proves health.
Upgrading n8n safely
Before an upgrade, back up the database, encryption key, and persistent files; verify you can restore them. Read release and migration notes, test the target version separately, and change N8N_VERSION deliberately. Then:
cd /opt/n8n
sudo docker compose pull
sudo docker compose up -d
Keep the previous image available while verifying the upgrade. An image rollback may be insufficient after database migrations; recovery can require the matching database backup. Avoid treating a redeploy button as a complete rollback plan.
Backups (beginner-simple approach)
At minimum, back up:
- A consistent Postgres dump (do not copy a live data directory as your only backup)
- n8n config/persistent files, any binary execution storage, and the encryption key
A straightforward DB dump example:
cd /opt/n8n
umask 077
sudo docker compose exec -T postgres pg_dump -U n8n n8n > n8n_backup.sql
-T disables the terminal allocation for redirected output. Check the exit code and stderr, protect the backup (it contains sensitive data), store it off-server, and run a restore drill in a separate environment. Postgres documents the scope and formats of pg_dump; it does not include cluster-wide roles or replace backing up the n8n encryption key.
3) Install n8n with Coolify (simpler ops, still Docker)
Coolify can be a big step up for beginners because it provides:
- A UI to deploy and update apps
- Built-in reverse proxy and SSL handling (depending on your configuration)
- Environment variable management
- Git-based deployments
Official Coolify docs:
Because Coolify evolves quickly, the exact clicks can differ by version, but the successful mental model stays the same: deploy the n8n container, attach persistent storage, set environment variables, and ensure you have a public URL with HTTPS.
Start with Coolify’s n8n service documentation, then inspect the generated configuration. A service template saves setup work; it does not remove owner-account setup, patching, or backup responsibilities.
Step 1: Install / access Coolify
Follow Coolify’s installation guide for your server:
Once installed, confirm:
- The Coolify reverse proxy is running (Coolify often uses a proxy like Traefik under the hood, depending on version/config).
- You can create a new “Application” (Docker-based).
Step 2: Create a new n8n application
You generally have two routes:
Route A: Deploy from a Docker image
Use the official n8n Docker image:
docker.n8n.io/n8nio/n8n:latest(or a pinned version tag)
In Coolify, create an app that runs that image and exposes port 5678.
Route B: Deploy from a Git repository containing a compose file
Coolify supports Docker Compose applications. Store a Compose file in a repo and let Coolify manage it, but adapt its networking: the Coolify proxy connects over a Docker network, so the VPS example’s host-loopback binding is not the proxy route. Configure the domain for the n8n service on container port 5678 and keep the database private; avoid publicly publishing 5678 or 5432.
This is useful when you want n8n + Postgres as a single stack.
Step 3: Configure persistent storage
n8n needs persistence. In Docker terms, n8n stores data in:
/home/node/.n8n
So in Coolify, add a persistent volume / storage mapping for that path.
If you deploy Postgres too, persist:
/var/lib/postgresql/data
Step 4: Configure environment variables (must match your domain)
In Coolify’s UI, set the same core environment variables you would in Compose. Refer to n8n’s official env var docs:
Common baseline for a public instance:
N8N_HOST=n8n.example.comN8N_PROTOCOL=httpsN8N_PORT=5678N8N_WEBHOOK_URL=https://n8n.example.com/for n8n 2.35+, orWEBHOOK_URLon older releasesN8N_EDITOR_BASE_URL=https://n8n.example.com/N8N_PROXY_HOPS=1when the Coolify proxy is the only hop; adjust for your actual chain- A persistent
N8N_ENCRYPTION_KEY, plus matchingTZandGENERIC_TIMEZONE
If you’re using Postgres, add the DB variables according to n8n documentation for Postgres configuration (via env vars).
Step 5: Attach a domain and enable HTTPS
In Coolify:
- Add the domain
n8n.example.comto the application - Enable HTTPS/SSL (Coolify can often request and renew Let’s Encrypt certificates automatically)
After that, confirm:
- You can access
https://n8n.example.com - Webhooks show as
https://n8n.example.com/webhook/...
Step 6: Updates and rollbacks
One of Coolify’s strengths is simplifying updates:
- You can redeploy with a click
- If using Git-based deploys, updates can be tied to pushes/tags
- If using an image tag, you can change the tag and redeploy
For n8n, it’s often better to pin versions rather than always running latest, especially in production. The official Docker docs cover image usage and tags:
Common troubleshooting (across all installs)
“My webhook test works locally but not from the internet”
Most often:
- You are not using a public URL (local only)
- Your version’s webhook base URL setting is missing or incorrect
- Your reverse proxy is not forwarding headers correctly
- HTTPS is missing or mixed (HTTP outside, HTTPS inside, etc.)
Start by checking what URL n8n believes it’s running on in the UI (and compare to your env vars).
“I can load the UI, but OAuth callbacks fail”
OAuth providers require exact redirect URLs. Ensure:
- Your public URL is stable and HTTPS
- The provider redirect URI matches n8n’s callback URL exactly
N8N_HOST,N8N_PROTOCOL,N8N_EDITOR_BASE_URL, and the public webhook base URL are correct
“502 Bad Gateway from Nginx”
Usually:
- n8n container isn’t running
- n8n is bound to the wrong interface/port
- Nginx is proxying to the wrong upstream (
127.0.0.1:5678must match your Docker port binding) - Check logs:
sudo docker compose logs -f n8nsudo tail -f /var/log/nginx/error.log
“Data disappeared after recreating the container”
That means persistence wasn’t configured correctly:
- Ensure your volume mapping includes
/home/node/.n8n - On VPS, ensure named volumes exist and are referenced in the Compose file
- On Coolify, ensure storage is configured and attached to the correct path
Which method should you choose?
If you’re a beginner developer, a practical progression is:
- Local Docker Compose for learning and building workflows quickly.
- VPS + Docker + Nginx when you need real webhooks, HTTPS, and full control (and you want to learn how production reverse proxies work).
- Coolify when you want “deploy like a platform,” reduce manual Nginx/SSL work, and manage apps in a UI—without giving up Docker.
Once the service is running, the stateful n8n agent guide takes the next step: choosing what belongs in conversation history, operational state, and document retrieval.
Official docs reference list (bookmark these)
- n8n Docker installation: https://docs.n8n.io/hosting/installation/docker/
- n8n environment variables: https://docs.n8n.io/hosting/configuration/environment-variables/
- Docker Engine install: https://docs.docker.com/engine/install/
- Docker Compose overview: https://docs.docker.com/compose/
- Nginx documentation: https://nginx.org/en/docs/
- Certbot (Let’s Encrypt): https://certbot.eff.org/
- Coolify documentation: https://coolify.io/docs
