Self-host n8n

Last updated:

Getting n8n to start on a server is the easy part. Self-hosting it well comes down to four settings that bite later if you skip them: the encryption key, the webhook URL, a pinned version and a closed port 5678. n8n's own guides put HTTPS in one file and Postgres in another, and spread those four across several more pages.

The software is free: n8n's Community Edition is "free with almost the complete feature set." You pay for the server.

This recipe hands the setup to your AI assistant. With the American Cloud MCP server connected, one prompt sizes the VM, shows you the monthly cost before anything is billed, creates the server, installs n8n with Postgres and HTTPS, and sets all four on day one.

What it costs

Self-hosting n8n on American Cloud costs $43.125 a month for the setup in this recipe. The VM's public IP is included.

ItemMonthly cost
VM: 2 vCPU, 4 GB RAM, 50 GB disk (monthly term)$43.125
Public IP (the network's own address)$0
Network created with the VM$0
Egress (webhook calls, API traffic, downloads)$0
Snapshot, optional$10 per 100 GB

The VM size is our pick: n8n publishes no minimum for a plain install. If workflows outgrow it, your assistant resizes the VM in place with scale_vm.

n8n Cloud prices by executions: Starter is €20 a month for 2,500 workflow executions and Pro is €50 a month for 10,000, both billed annually. On your own VM the bill doesn't move with your execution count, and webhook traffic costs nothing extra.

Why Claude Code for this

Any MCP client can create the infrastructure. But installing n8n also means running commands on the server: SSH in, install Docker, write the compose file and the .env, bring the stack up. Claude Code combines the American Cloud tools with your terminal, so one session can provision the VM and set up n8n on it without you switching tools. That's the setup this recipe assumes. Cursor and the other clients work too. You'll just run the SSH steps yourself when the assistant tells you to.

Provisioning is a write operation. You'll need write access: set the app to Full access in Connected apps on the hosted server, or use a Full access API token and the --allow-writes flag on the local server. See the overview for setup and safety details. To explore first, set the app to Read-only, then switch to write access when you're ready to build.

Before you start

  • A domain you control. n8n's HTTPS setup needs an A record pointing a subdomain, such as n8n, at the server.
  • The MCP server connected to your assistant with write access, as the note above describes.
  • On the local MCP server, the DNS tools are off by default. Start it with --services all, or add dns to your --services list.
  • An email address for Let's Encrypt, which issues the HTTPS certificate.

The one prompt that does it

Open Claude Code and paste this, filling in the placeholders. Read the cost estimate it shows you before approving anything.

text
I want to self-host n8n on American Cloud at n8n.{your-domain.com}, with
Postgres and HTTPS. Plan it out first, then walk through it step by step:
 
1. List the available regions, Ubuntu images and VM packages. Size the VM at
   2 vCPU, 4 GB of RAM and a 50 GB disk.
2. Check whether my SSH key is already registered. If not, register my
   public key ~/.ssh/id_ed25519.pub with create_ssh_key. If I have no key
   pair, ask me before you run ssh-keygen.
3. Show me the monthly cost estimate for the VM before creating anything.
   Wait for me to confirm.
4. Create an Ubuntu VM with that SSH key and open inbound ports 22, 80 and
   443 only. Do not open 5678. Wait until it's running and has a public IP.
5. Over SSH, install Docker Engine and the Docker Compose plugin.
6. In ~/n8n, build a compose file from n8n's Docker Compose guide for a
   cloud server (Traefik and Let's Encrypt), and swap SQLite for Postgres
   using the "Use PostgreSQL instead of SQLite" section of n8n's "Install
   using Docker Compose" guide. Take only the Postgres parts from that guide.
   Tell me plainly that the result is your merge of two n8n guides. In it:
   - pin n8nio/n8n to the current stable tag from n8n's GitHub releases
     (2.48.4 on 17 November 2026), and pin Traefik to a version tag too
   - publish 5678 on 127.0.0.1 only
   - drop --api.insecure=true from Traefik
   - set N8N_HOST=n8n.{your-domain.com}, N8N_PROTOCOL=https,
     N8N_WEBHOOK_URL=https://n8n.{your-domain.com}/ and N8N_PROXY_HOPS=1
   - use {[email protected]} for Let's Encrypt and {America/Chicago}
     as the timezone
7. Generate N8N_ENCRYPTION_KEY and the Postgres password on the server and
   write them to ~/n8n/.env. Never print their values in this chat. Give me
   one SSH command that prints the encryption key, so I can save it in my
   password manager.
8. DNS: check whether {your-domain.com} is already a zone on American Cloud.
   If not, create the zone and tell me to set my registrar's nameservers to
   ns1.americancloud.org and ns2.americancloud.org. Then add an A record
   with Hostname n8n, Type A, Value the VM's public IP.
9. Once n8n.{your-domain.com} resolves to the VM, run docker compose up -d
   and confirm Traefik got a certificate and n8n answers over HTTPS.
 
Then give me the URL to open.

What your assistant will do

[ What the prompt does ]
The steps the prompt walks throughFirst row, before anything is billed: list regions, images and packages; show the monthly price; you approve; create the VM. Second row, on the server over SSH: install Docker; write the compose file and the .env file; add the DNS A record; run docker compose up.Before anything is billedList optionsShow priceYou approveCreate VMOn the server, over SSHGet DockerCompose .envA recordcompose up
Nothing is created until you approve the price. Everything after that happens on your VM, over SSH.

Here's the sequence, tool by tool:

  1. Survey the options. It calls list_regions, list_images (filtered to Ubuntu) and list_vm_packages to find a region near you, a current Ubuntu LTS image and a package for 2 vCPU and 4 GB.

  2. Sort out the SSH key. It calls list_ssh_keys to see what's registered. If your key isn't there, it registers your existing public key (for example ~/.ssh/id_ed25519.pub) with create_ssh_key. The private key stays on your machine and never passes through the chat.

  3. Price it first. It calls get_cost_estimate_vm with the exact region, package, disk size and image, and shows you the monthly number before creating anything. Nothing is billed until you approve.

  4. Create the server. On your go-ahead, create_vm provisions the VM. The same call carries keypairs to install your SSH key and networkAccess.inboundPorts to open 22, 80 and 443. Opening a port this way sets up the firewall rule and the port forwarding together. The assistant polls get_vm until the VM is running with a public IP.

  5. Install Docker. Now in the terminal, it installs Docker Engine and the Compose plugin over SSH.

  6. Build the compose file. n8n's Docker Compose guide for a cloud server runs Traefik with Let's Encrypt in front of n8n on SQLite, and its Install using Docker Compose guide has the section that swaps in Postgres. The assistant merges the two, so the file on your server is our combination of two n8n guides, not an official n8n file. It keeps the Traefik guide's n8n_data volume at /home/node/.n8n, which holds the encryption key even when the workflows live in Postgres. It also leaves out a separate task-runner container, as the Traefik guide does, so n8n runs tasks in its default internal mode.

  7. Write the secrets on the server. It generates the encryption key and the Postgres password on the VM and writes them straight into ~/n8n/.env. The values never pass through the chat. You get one command to print the key yourself (how to keep it).

  8. Point the domain at it. It calls list_dns_zones to see whether your domain is already hosted. If not, create_dns_zone adds it, and you set your registrar's nameservers to ns1.americancloud.org and ns2.americancloud.org. Then create_dns_record adds the record:

    HostnameTypeValue
    n8nAthe VM's public IP
  9. Bring it up. Once the name resolves, it runs docker compose up -d. Traefik requests the certificate, redirects port 80 to HTTPS, and passes traffic to n8n on port 5678 over the private Docker network.

When it's done, the assistant hands you https://n8n.{your-domain.com}. Open it and finish setup in n8n.

Tell the assistant to explain each step before it runs it if you want to follow along: "narrate what you're about to do and why." Destructive operations are flagged regardless, and clients that support confirmations will prompt you before anything irreversible.

The settings that break self-hosted n8n

Save the encryption key

n8n encrypts every saved credential with a key it generates on first launch and keeps in the .n8n folder. Lose that folder, or rebuild the container without it, and n8n makes a new key that can't read the credentials you already saved. n8n's backup docs say that without the key, "a restored database or encrypted credential export can't be decrypted."

The fix is to set N8N_ENCRYPTION_KEY yourself and keep a copy off the server. The assistant gives you a command like this one. Run it, then paste the key into your password manager:

bash
ssh -i ~/.ssh/<your-key> cloud@<public-ip> 'grep N8N_ENCRYPTION_KEY ~/n8n/.env'

Set the webhook URL

Behind a proxy, n8n's default webhook URLs are wrong. n8n builds the webhook URL "by combining N8N_PROTOCOL, N8N_HOST and N8N_PORT. If n8n runs behind a reverse proxy, that won't work." You'll see webhook URLs that point at port 5678, which nothing outside the server can reach.

Set the public URL yourself, and tell n8n it sits behind one proxy:

bash
N8N_HOST=n8n.example.com
N8N_PROTOCOL=https
N8N_WEBHOOK_URL=https://n8n.example.com/
N8N_PROXY_HOPS=1

N8N_WEBHOOK_URL replaces WEBHOOK_URL. The new name works from n8n 2.30.0, and the old one is deprecated from 2.35.0: it still works, but n8n logs a warning. n8n's Traefik guide doesn't set N8N_PROXY_HOPS; n8n's reverse-proxy page says to set it to 1.

Pin the version

n8n's Traefik compose file uses image: n8nio/n8n with no tag, so every docker compose pull takes whatever latest points to that day. Pin a specific image tag instead. The prompt pins n8nio/n8n:2.48.4, the current stable release on 17 November 2026. Check n8n's GitHub releases for the current one when you run it.

Keep 5678 off the internet

n8n listens on port 5678, and only Traefik should talk to it. The prompt puts two locks on 5678. The VM opens only 22, 80 and 443, and the compose file publishes 5678 on 127.0.0.1 only, so even a firewall rule added by mistake later wouldn't expose it. Watch for this if you copy from the withPostgres example in n8n's n8n-hosting repo, which publishes 5678 on every interface.

[ What runs on the VM ]
What runs on the VM and which ports are openPorts 22, 80 and 443 are open to the internet; port 5678 is not. Inside the VM, web traffic on 80 and 443 goes to Traefik, which handles HTTPS with Let's Encrypt and passes requests to n8n on port 5678 over the private Docker network. n8n stores workflows and data in Postgres, and its n8n_data volume holds the encryption key.Open to the internet22 SSH80 HTTP443 HTTPS5678 shutYour VMTraefikTLS on 443n8nport 5678Postgresworkflows, datan8n_dataencryption key
Only 22, 80 and 443 reach the VM. Traefik hands web traffic to n8n over the private Docker network, and the n8n_data volume holds the encryption key.

Updates and backups

You own updates once n8n is running, and n8n says to update at least once a month. Its advisories show why: GHSA-q8rc-7m84-mfvj, rated high, was fixed in 2.48.3.

[ Every update, in this order ]
The order of an n8n updateFirst row, back up first: snapshot the VM, dump the Postgres database, copy the n8n_data volume. Second row, then update: change the image tag, run docker compose pull, down and up -d, and check that n8n loads over HTTPS with your workflows and credentials.Back up firstSnapshot VMDump PostgresCopy n8n_dataThen updateChange the tagpull, down, upCheck it loads
Rolling the tag back won't undo database migrations, so the backups come first.

Don't count on rolling back by changing the tag. n8n's update page says "changing the image tag or Helm release back to the older version doesn't reverse database migrations." If an update goes wrong, you restore from a backup, so this prompt takes one before it touches the tag:

text
Update n8n on my VM to the latest stable release. First check n8n's GitHub
releases and release notes and tell me about any breaking changes. Show me
the snapshot cost, then snapshot the VM, dump the Postgres database and copy
the n8n_data volume. Then change the image tag in ~/n8n's compose file and
run docker compose pull, docker compose down and docker compose up -d.
Confirm n8n answers over HTTPS and my workflows and credentials load.

Between updates, dump Postgres nightly to object storage, as Backups and restore shows.

Can I use self-hosted n8n for my business?

Yes, for your own internal business purposes. n8n's Sustainable Use License says: "You may use or modify the software only for your own internal business purposes or for non-commercial or personal use. You may distribute the software or provide it to others only if you do so free of charge for non-commercial purposes."

Check the license before you host n8n for other people. Features are a separate question: the Community Edition doesn't include projects, SSO, sharing, Git, external secrets or log streaming. Those need a paid Business or Enterprise license key.

When one VM isn't enough

n8n's queue mode spreads executions across worker processes and needs Redis. Plan it as its own project, and reach for it only when a resized VM can't keep up.

Troubleshooting

The browser shows a certificate error. Traefik can't get a certificate until n8n.{your-domain.com} resolves to the VM and ports 80 and 443 are open. Ask your assistant to "check what n8n.{your-domain.com} resolves to, and confirm 80 and 443 are open with list_firewall_rules."

The dashboard doesn't load. Ask your assistant to "SSH in and show me the logs for the Traefik and n8n containers." The logs show whether Traefik is routing to n8n and whether n8n reached Postgres.

Saved credentials won't decrypt after a restore or rebuild. The encryption key changed. Put the key from your password manager back in ~/n8n/.env and restart the stack (why the key matters).

Next steps

Contact us