Run n8n Locally — Deployment Guide

Deploy n8n Locally with Docker

Spin up a production‑ready n8n instance on your own machine using Docker Compose, PostgreSQL, and Nginx. Follow the six steps below and you’ll have a secure, self‑hosted automation platform in about 30 minutes.

Prepare your environment

Install Docker Engine and the Compose plugin on a Linux server (Ubuntu 22.04/24.04 is recommended). Make sure ports 80 and 443 are open in your firewall, and point a domain (e.g. n8n.yourdomain.com) to the server’s IP.

For a fully automated setup, check out our Docker Node Deployment: Port, Volume & Compose Configuration.

Create the project and configure environment variables

Create a directory ~/n8n-stack and inside it a .env file with the essential variables:

  • DOMAIN=n8n.yourdomain.com
  • N8N_HOST=${DOMAIN} and N8N_PROTOCOL=https
  • WEBHOOK_URL=https://${DOMAIN}/
  • N8N_ENCRYPTION_KEY (generate with openssl rand -hex 32)
  • DB_TYPE=postgresdb and PostgreSQL connection details

Read the full environment variable reference in our Database Configuration Guide.

Write the docker‑compose.yml

Define four services: n8n (main app), n8n-worker (queue‑mode execution), postgres (PostgreSQL 16‑alpine), and redis (Redis 7‑alpine). Mount named volumes for persistent data and bind n8n to 127.0.0.1:5678 so only the reverse proxy can reach it.

Grab a complete, tested Compose file from the Full Production Stack Guide.

Set up the reverse proxy and SSL

Add an Nginx service (or Caddy for zero‑config TLS) that terminates HTTPS on port 443 and proxies requests to http://n8n:5678. Forward the X‑Forwarded‑For, X‑Forwarded‑Proto, and Host headers, and set a generous proxy_read_timeout for long‑running workflows.

For step‑by‑step Nginx configuration, see our Self‑Host Security Hardening Guide.

Launch and verify the stack

Run docker compose up -d and watch the logs. Once all containers are healthy, visit https://n8n.yourdomain.com. Create your owner account and confirm that the webhook URL is correct (it should start with https://).

For guidance on scaling beyond a single server, explore the Scaling & Concurrency Guide.

Harden the instance

Enable Basic Auth, block Code‑node access to process.env, disable the ExecuteCommand node, restrict file access, and configure UFW to only allow ports 80 and 443. Pin your Docker image tags to avoid surprise upgrades.

The definitive hardening checklist lives in the Security Hardening Guide.

Deployment Flow (Mermaid)

flowchart TD
    A[Install Docker & Docker Compose] --> B[Create .env with secrets & domain]
    B --> C[Write docker-compose.yml
n8n, worker, postgres, redis, nginx] C --> D[Start stack: docker compose up -d] D --> E[Verify health checks
Postgres, Redis, n8n] E --> F[Access n8n at https://yourdomain.com
Create owner account] F --> G[Enable Basic Auth & Hardening] G --> H[Production Ready ✅]