What this self-managed setup includes
This guide runs one n8n instance and a Caddy HTTPS proxy on a fresh Linux VPS. It uses n8n’s default SQLite storage for a small starting deployment, with data in a named volume. This is a self-managed application setup, with no high-availability design or managed n8n service included. A busy or business-critical installation needs its own database, scaling, monitoring and recovery decisions.
- A fresh Ubuntu LTS server supported by Docker, sudo access, and enough spare CPU, memory and disk for your actual workflows and their data.
- A domain you control, such as n8n.example.com, with an A record pointing directly to the server. Add an AAAA record only after verifying IPv6 connectivity.
- TCP ports 80 and 443 available for Caddy, and working SSH administration. Check for existing applications using those ports before changing a server.
- Direct DNS to this VPS for the example below. Adding a CDN or another reverse proxy changes both the trusted proxy configuration and the temporary IP restriction.
- Your administration computer’s public IP address, a password manager, and a separate place to keep encrypted backups.
There is no reliable universal RAM-to-workflow formula. Large JSON payloads, binary files, Code nodes, concurrent executions and manual runs can have different memory demands. Start with representative workflows, observe peaks and leave headroom for the operating system, proxy and backups. Keep external API charges, domain renewal and backup storage separate from the VPS bill.
1. Install Docker and record the images you will deploy
Install Docker Engine and the Compose plugin using Docker’s official Ubuntu instructions. Review n8n’s current stable release notes before choosing an image. The following pulls the official n8n default image and Caddy’s Alpine image, then prints immutable image references. Copy the complete repository@sha256 values into the configuration in the next step. This records the images you actually selected instead of leaving the deployment on moving tags.
- Docker: install Engine and Compose on Ubuntu →
- n8n: current stable release notes →
- n8n: Docker Compose server installation →
sudo docker version
sudo docker compose version
sudo apt update
sudo apt install nano openssl curl
sudo docker pull n8nio/n8n
sudo docker pull caddy:2-alpine
sudo docker image inspect n8nio/n8n --format '{{index .RepoDigests 0}}'
sudo docker image inspect caddy:2-alpine --format '{{index .RepoDigests 0}}'
install -d -m 0700 ~/n8n-vps
cd ~/n8n-vps
mkdir -p caddyUse a fresh directory for this guide. If you already run n8n, preserve its database, original encryption key and deployment configuration before planning a migration. Do not initialize a replacement key over an existing installation.
2. Create the hostname, image pins and encryption key
Create a private .env file once. n8n uses the encryption key to protect stored credentials; generating a different key later is not a password reset and can prevent those credentials from being decrypted. The guard below leaves an existing .env untouched. Keep this file out of Git, support tickets and screenshots.
cd ~/n8n-vps
if [ -e .env ]; then
printf '%s\n' '.env already exists; keep its original encryption key.'
else
(umask 077; printf 'N8N_ENCRYPTION_KEY=%s\n' "$(openssl rand -hex 32)" > .env)
fi
chmod 600 .env
nano .envKeep the generated N8N_ENCRYPTION_KEY line. Add the four lines below, replacing the hostname and both image placeholders with the exact digest references printed earlier. Use only a hostname in N8N_HOST, without https:// or a path. Etc/UTC is a starting timezone; change it to the timezone your schedules require.
N8N_HOST=n8n.example.com
N8N_IMAGE=REPLACE_WITH_N8N_REPOSITORY_AT_SHA256_DIGEST
CADDY_IMAGE=REPLACE_WITH_CADDY_REPOSITORY_AT_SHA256_DIGEST
GENERIC_TIMEZONE=Etc/UTC3. Keep the n8n port private and persist its data
Create compose.yaml in ~/n8n-vps. Caddy is the only service with published host ports. It reaches n8n:5678 through the Compose network, while n8n can still reach external APIs. The n8n_data volume survives ordinary container replacement. Caddy has its own certificate and configuration volumes; its container does not receive your n8n encryption key.
name: n8n-vps
services:
n8n:
image: "${N8N_IMAGE:?Set N8N_IMAGE in .env}"
restart: unless-stopped
environment:
N8N_HOST: "${N8N_HOST:?Set N8N_HOST in .env}"
N8N_PORT: "5678"
N8N_PROTOCOL: https
N8N_EDITOR_BASE_URL: "https://${N8N_HOST}/"
N8N_WEBHOOK_URL: "https://${N8N_HOST}/"
N8N_PROXY_HOPS: "1"
N8N_ENCRYPTION_KEY: "${N8N_ENCRYPTION_KEY:?Keep the original encryption key in .env}"
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
NODE_ENV: production
GENERIC_TIMEZONE: "${GENERIC_TIMEZONE:-Etc/UTC}"
TZ: "${GENERIC_TIMEZONE:-Etc/UTC}"
volumes:
- n8n_data:/home/node/.n8n
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
caddy:
image: "${CADDY_IMAGE:?Set CADDY_IMAGE in .env}"
restart: unless-stopped
environment:
N8N_HOST: "${N8N_HOST:?Set N8N_HOST in .env}"
ports:
- "80:80/tcp"
- "443:443/tcp"
volumes:
- ./caddy:/etc/caddy:ro
- caddy_data:/data
- caddy_config:/config
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
volumes:
n8n_data:
caddy_data:
caddy_config:The public editor and webhook addresses use HTTPS even though Caddy connects to the application’s internal HTTP port. Current n8n documentation uses N8N_WEBHOOK_URL; older guides may show the deprecated WEBHOOK_URL. N8N_PROXY_HOPS=1 matches this single-proxy topology. Caddy supplies the forwarded host, protocol and client address headers. Reassess these settings if you add another proxy.
4. Start HTTPS with restricted first-time account setup
Create caddy/Caddyfile with the following content. Replace 203.0.113.10 with your administration computer’s public IP, not the VPS address. Add your public IPv6 address on the same matcher line if your browser connects over IPv6. During setup this allows only those addresses to reach the application. It assumes clients connect directly to Caddy, with no CDN in front.
{$N8N_HOST} {
@outside_admin not remote_ip 203.0.113.10
respond @outside_admin "Setup access is restricted" 403
reverse_proxy n8n:5678
}Caddy can obtain and renew a public certificate when the hostname resolves to this server, ports 80 and 443 are reachable and its data storage is writable. Validate the configuration without printing the expanded secret values, then start the services.
cd ~/n8n-vps
sudo docker compose config --quiet
sudo docker compose run --rm --no-deps caddy caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
sudo docker compose up -d
sudo docker compose ps
sudo docker compose logs --tail=50 n8n caddyOpen https://n8n.example.com from the allowed computer, using your real hostname. Create the owner account with a strong, unique password and keep its recovery details. Sign out and verify that returning to the site shows login, not a fresh owner-setup screen. If setup or HTTPS is not working, leave the IP restriction in place while diagnosing it.
Once the owner account is established, decide whether the installation needs public webhooks. For public access, remove only the @outside_admin and respond lines from caddy/Caddyfile, leaving the hostname and reverse_proxy block. Validate and reload Caddy using the commands below. If you keep the restriction, external services outside the allowlist cannot call your webhooks.
sudo docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
sudo docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile5. Verify login, webhook URLs and a small workflow
- From your own computer, open the hostname over HTTP and confirm it redirects to HTTPS with a valid certificate. Sign in again and check that the editor stays connected.
- Create a small workflow using a manual trigger and a simple data transformation before adding credentials or actions that contact customers, modify records or incur external API charges.
- For a webhook workflow, inspect the URL displayed by n8n. It should use your public https:// hostname, with no localhost address or :5678 port.
- Use the test URL only while n8n is listening for a test event. After publishing the workflow, use its production URL. Configure authentication or verify the sender’s signature as appropriate before accepting real requests.
- Check the workflow’s timezone and execution result. A successful browser login does not verify incoming webhooks, scheduled runs or the permissions of a connected service.
cd ~/n8n-vps
sudo docker compose ps
sudo docker compose logs --tail=100 n8n caddy
sudo docker stats --no-stream
df -h
sudo docker system dfContainer log rotation does not cap database size, retained execution data or workflow files. Set an appropriate retention policy and monitor disk usage as the workload grows. Review logs privately: workflow payloads and integration errors can contain sensitive information.
6. Make a consistent backup and test recovery
For this SQLite setup, stop n8n before copying its data folder so the database is not changing during the copy. Plan the interruption: workflows and webhooks are unavailable while it is stopped. Save the entire /home/node/.n8n folder and the deployment files, including the original .env. A workflow export alone is not a full instance backup.
cd ~/n8n-vps
N8N_BACKUP_DIR="$HOME/n8n-backups/$(date -u +%Y%m%dT%H%M%SZ)"
install -d -m 0700 "$N8N_BACKUP_DIR"
sudo docker compose stop n8n
sudo docker compose cp -a n8n:/home/node/.n8n "$N8N_BACKUP_DIR/n8n-data"
sudo cp -a .env compose.yaml caddy "$N8N_BACKUP_DIR/"
sudo docker compose start n8nTransfer the backup securely to separate storage and protect it as credential-bearing data. A copy on the same VPS cannot recover a lost server. Test restoring on an isolated instance with the recorded image and original key, without letting restored schedules or integrations act on live systems. External databases, storage or custom-node paths added later need their own backups.
7. Update deliberately and diagnose the failing layer
Pinned images do not upgrade automatically. Review release notes, take a fresh consistent backup and test the proposed release separately. Pull the selected release, inspect its digest and change the appropriate image reference in .env. Then run docker compose up -d and repeat login, webhook and workflow checks. Keep the previous image and matching backup: a database migration can make changing only the image insufficient for rollback.
| Symptom | Check before changing the server |
|---|---|
| 403 during first setup | The temporary Caddy IP restriction, your actual public IPv4/IPv6 address and whether a CDN is unexpectedly in front of Caddy. |
| Certificate error or timeout | DNS A/AAAA records, provider firewall, conflicting web servers, Caddy logs and public reachability of ports 80/443. |
| 502 response from Caddy | Whether n8n is running and reachable as n8n:5678 on the Compose network. localhost inside Caddy points to Caddy itself. |
| Webhook URL has localhost, HTTP or port 5678 | N8N_HOST, N8N_EDITOR_BASE_URL, N8N_WEBHOOK_URL and the actual proxy hop count. Recreate the service after changing its environment. |
| Test webhook works but production does not | The exact test versus production URL, workflow publication state, sender authentication, proxy restrictions and execution details. |
| Owner setup appears again after an update | The project name, mounted volume and original database. Stop and locate the existing data before creating another owner or deleting volumes. |
| Saved credentials cannot be decrypted | The original encryption key and the backup that belongs with this database. Generating a new key does not recover old credentials. |
| Container exits or workflows run out of memory | Exit logs, peak memory, disk space, payload sizes and concurrency. Reduce unnecessary data or batch work before assuming a plan size fixes every failure. |
Know the license and the work you are taking on
n8n’s Community edition is distributed under its Sustainable Use License. Your own organization’s internal automation and offering a hosted n8n product to other organizations are different use cases. n8n’s current licensing guidance identifies externally accessible workflow building and hosting n8n as a service as cases requiring a commercial license. Review the terms for your intended use; renting a VPS does not grant those rights.
The server price is only one part of the operating cost. Include domain renewal, independent backups, external APIs and your time for updates, monitoring and recovery. Compare the payable billing total and renewal terms, then choose a Linux configuration based on measured workload and location needs.
Common questions
Does VPS Ray install or manage n8n for me?
This guide describes a self-managed deployment. It does not include one-click installation, application administration or a managed n8n service. You handle the application, operating system, security settings, monitoring, updates and backups.
How much RAM does n8n need on a VPS?
It depends on the workflows, payloads, concurrency and other services. Measure representative peak runs and include operating-system and proxy headroom. A file-heavy or highly concurrent workflow can behave very differently from a short scheduled API request.
Why is port 5678 not open to the internet?
Caddy connects to n8n:5678 inside the Compose network. Public users and webhook senders connect to the HTTPS hostname on port 443. Publishing an additional application port is unnecessary for this topology.
Can I restore n8n from a workflow export?
An export is useful for moving selected workflows, but it does not replace a full instance backup. Keep the persistent database and other required data, deployment settings and original credential encryption key, and test the restore process.
Can I sell access to this n8n installation?
Do not assume the Community license permits a hosted or white-label n8n service. Review n8n’s current licensing guidance for your model and obtain the required commercial license before offering access outside your organization.
Official documentation
Documentation reviewed November 6, 2026. Check current product terms and the linked documentation before choosing a setup. The examples in this guide have not been run on your VPS.
- n8n: Docker Compose server setup
- n8n: reverse proxy webhook configuration
- n8n: deployment environment variables
- n8n: custom encryption key
- n8n: backup and restore
- n8n: update guidance
- n8n: memory issues
- n8n: webhook node behavior and authentication
- n8n: current license guidance
- n8n: license terms
- Docker: Ubuntu installation
- Docker: Compose networking
- Docker: published ports and firewalls
- Docker: local logging and rotation
- Docker: image inspection
- Docker: copy service files
- Caddy: run with Docker Compose
- Caddy: automatic HTTPS
- Caddy: IP matchers
- Caddy: reverse proxy and forwarded headers