n8n is a popular and open-source workflow automation tool, which you can self-host on a Hetzner Cloud server using Docker Compose and Caddy as a reverse proxy. This detailed tutorial ensures a smooth setup while highlighting best practices for security and maintenance.
What you need
Before starting, ensure you meet these requirements:
- Docker CE installed on your server
- A domain name pointed to your server’s IP address
Technologies used in this guide
- Cloud Server (Docker CE pre-installed)
- Docker & Docker Compose for containerized deployment
- Caddy as the reverse proxy
- n8n (latest stable version)
We’ve partnered with UpCloud to offer you €25 in free credits—get started with cloud servers and storage for self-hosting and more!
Deploy n8n using docker-compose
Step 1: Prepare the server
In this step, you will:
- Update the system packages.
- Install the Docker Compose plugin.
- Clone the n8n setup repository.
- Create required Docker volumes.
Run the following commands on your server via SSH:
# Update the system packages
apt update && apt -y upgrade
# Install Docker Compose plugin
apt install docker-compose-plugin
# Clone the n8n setup repository
git clone https://github.com/n8n-io/n8n-docker-caddy.git
cd n8n-docker-caddy
# Create necessary Docker volumes
docker volume create caddy_data
docker volume create n8n_data
Step 2: Open required ports
Configure your server’s firewall:
sudo ufw allow 80 # Allow HTTP traffic
sudo ufw allow 443 # Allow HTTPS traffic
Step 3: Set Up DNS for Your Subdomain
Set up DNS records for your domain with your registrar:
- Type:
A
- Host:
n8n
(or your preferred subdomain) - Value: Your server’s public IP address
- TTL:
3600
(or default)
Wait for DNS propagation to complete, which may take a few minutes.
Step 4: Update Environment Variables
Edit the .env
file and update the following variables:
- N8N_HOST: e.g.,
n8n.example.com
- N8N_PROTOCOL: Use
https
- N8N_PORT: Default is
5678
- N8N_ENCRYPTION_KEY: Set a secure encryption key
- DOMAIN_NAME: Your domain (e.g.,
example.com
) - SUBDOMAIN: Subdomain for n8n (e.g.,
n8n
) - N8N_BASIC_AUTH_USER: Admin username for basic auth
- N8N_BASIC_AUTH_PASSWORD: Strong admin password
Step 5: Set Up Caddy as a Reverse Proxy
Edit the Caddy configuration file:
nano caddy_config/Caddyfile
Ensure the Caddyfile
includes configurations for HTTPS, routing traffic to your n8n instance, and SSL certificate automation.
Replace the domain placeholder with your subdomain in all configurations, then start n8n and its dependencies:
n8n.example.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
}
Step 6: Launch n8n
Now, simply start your n8n instance.
# Example command to start n8n (adjust based on your setup, e.g., Docker or npm):
docker-compose up -d
Verify Accessibility:
Visit your domain in a web browser (e.g., https://n8n.yourdomain.com
) to confirm that n8n is accessible.
That’s it—you’re done! 🎉
Leave a Reply