n8n is a powerful open-source workflow automation tool, enabling you to automate repetitive tasks by connecting different apps and services. In this guide, you’ll learn how to set up n8n from zero on any cloud provider or even a bare-metal server, and expose it securely through your own custom domain — all in a cloud-agnostic way.
Why Use n8n?
- Open-source and self-hostable
- Highly customizable workflows
- Supports over 200 apps natively
- Extendable with custom nodes
- Free to run on your own infrastructure
Overview of What We’ll Cover
- Prerequisites
- Setting Up a Server
- Installing Docker and Docker Compose
- Running n8n with Docker
- Setting Up a Reverse Proxy with HTTPS using Caddy
- Pointing Your Domain and Configuring DNS
- Securing and Managing Your Setup
1. Prerequisites
- A server (cloud VM or bare-metal) running Linux (Ubuntu recommended)
- A domain name you own and control DNS records for
- Basic command line and SSH access knowledge
- Docker and Docker Compose installed (we’ll install them in the guide)
- Optional: An Elastic IP or static IP on your server for consistent access
2. Setting Up Your Server
Choose any cloud provider (AWS, Google Cloud, Azure, DigitalOcean, Linode, Vultr, Hetzner, etc.) or your own Linux server.
- Ubuntu 20.04 or 22.04 LTS is preferred.
- Make sure ports 80 and 443 are open for HTTP/HTTPS traffic.
- SSH into your server to run the commands.
3. Install Docker & Docker Compose
Docker makes deployment straightforward and consistent. Run these commands on your server:
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install -y docker.io docker-compose unzip curl
# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker
# Verify Docker installed correctly
docker --version
docker-compose --version
4. Run n8n Using Docker Compose
Create a project directory and define your Docker Compose file.
mkdir ~/n8n
cd ~/n8n
Create a file named docker-compose.yaml
with this content:
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- GENERIC_TIMEZONE=America/Chicago # Change timezone as needed
- TZ=America/Chicago
- N8N_PROTOCOL=http
- N8N_HOST=yourdomain.com # Replace with your domain
- N8N_PORT=5678
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
Then start your container:
docker-compose up -d
You should now be able to reach n8n on http://your-server-ip:5678
(replace with your actual IP).
5. Setup Reverse Proxy and HTTPS with Caddy
To make your n8n instance accessible securely via HTTPS and your domain, we use Caddy — an automatic HTTPS reverse proxy.
Create a Caddyfile
in the same directory:
yourdomain.com {
reverse_proxy n8n:5678
}
Update your docker-compose.yaml
to add Caddy service:
version: "3"
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
restart: unless-stopped
environment:
- GENERIC_TIMEZONE=America/Chicago
- TZ=America/Chicago
- N8N_PROTOCOL=http
- N8N_HOST=yourdomain.com
- N8N_PORT=5678
volumes:
- n8n_data:/home/node/.n8n
caddy:
image: caddy:latest
container_name: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
volumes:
n8n_data:
caddy_data:
caddy_config:
Restart the services:
docker-compose down
docker-compose up -d
6. Point Your Domain DNS
- Create an A record in your domain's DNS management panel pointing your domain (e.g.,
yourdomain.com
) to your server's public IP address. - If using a cloud provider with Elastic IPs or static IPs, make sure this IP doesn’t change.
- It may take some time for DNS changes to propagate.
7. Secure and Manage Your Setup
- Caddy automatically provisions SSL certificates via Let's Encrypt.
- Your n8n is now accessible securely at
https://yourdomain.com
. - Use
docker logs caddy
ordocker logs n8n
to debug if necessary. - Backup your
/home/node/.n8n
data volume regularly. - Consider setting up firewall rules to restrict access.
Conclusion
You now have a self-hosted n8n workflow automation instance running behind a secure HTTPS domain — all set up in a cloud-provider-agnostic way! This setup allows full control over your automation workflows with no vendor lock-in.
If you want to scale or add databases like Postgres, n8n supports that too with minor config changes.
Happy automating! 🚀
Top comments (0)