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 (View guide)
- A domain name pointed to your server’s IP address
Technologies used in this guide
- Hetzner Cloud Server (image: Docker CE pre-installed)
- Docker & Docker Compose for containerized deployment
- Caddy as the reverse proxy
- n8n (latest stable version)
Note: We’ll use Hetzner Cloud as our hosting provider, but you can use any other provider as well, that comes with a pre-installed version of Docker CE or where you can self install Docker CE.
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:
nano .env
Update the following variables:
N8N_HOST
– e.g.,n8n.example.com
N8N_PROTOCOL
– Usehttps
N8N_PORT
– Default is5678
N8N_ENCRYPTION_KEY
– Set a secure encryption keyDOMAIN_NAME
– Your domain (e.g.,example.com
)SUBDOMAIN
– Subdomain for n8n (e.g.,n8n
)N8N_BASIC_AUTH_USER
– Admin username for basic authN8N_BASIC_AUTH_PASSWORD
– Strong admin password
Step 5: Set Up Caddy as a reverse proxy
Edit the Caddy configuration file:
nano caddy_config/Caddyfile
Replace the domain placeholder with your subdomain:
n8n.example.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
}
Step 6: Launch n8n
Start n8n and its dependencies:
docker compose up -d
Verify that the services are running:
docker ps
Visit your domain in a web browser to confirm that n8n is accessible.
That’s it, you’re done.
Maintenance Commands
Stop n8n
docker compose stop
Update n8n
# Pull the latest image
docker compose pull
# Restart the updated containers
docker compose down && docker compose up -d
Troubleshooting
Common Issues
- Cannot access the n8n interface:
- Verify DNS records and propagation.
- Ensure the server firewall allows ports 80 and 443.
- Confirm Docker containers are running.
- Docker Compose errors:
- Check the
.env
file for misconfigurations. - Restart the Docker service:
sudo systemctl restart docker
. - Inspect container logs with
docker logs <container_name>
.
- Check the
- SSL/TLS certificate errors:
- Verify Caddy’s configuration file.
- Check DNS settings for accuracy.
- Ensure ports 80 and 443 are open.
Security Best Practices
- Use strong, unique passwords for n8n access.
- Regularly update Docker, n8n, and server packages.
- Enable automated backups to prevent data loss.
- Monitor server resources to detect anomalies.
- Use SSH key authentication instead of password-based SSH login.
FAQ
n8n is an open-source workflow automation tool that allows you to connect various applications and automate repetitive tasks. It supports integrations with popular apps and services, enabling users to create complex workflows with little or no code.
Yes, n8n is open-source and free to self-host. There is also a cloud-hosted version with subscription plans for those who prefer a managed solution.
Minimum requirements for running n8n:
2GB RAM
1 CPU core
20GB storage
Docker or Node.js environment
PostgreSQL or SQLite database
Yes, n8n supports numerous integrations with third-party tools and apps. You can connect n8n to various services like Slack, Google Sheets, GitHub, and more, using built-in nodes or custom integrations.
n8n provides options for secure data handling, including environment variables for storing sensitive information and support for HTTPS with SSL certificates. For additional security, it is recommended to use secure networking practices and keep n8n updated.
No, n8n is designed to be user-friendly, allowing you to create workflows with a visual editor. However, basic knowledge of programming or APIs can help if you want to create custom nodes or perform advanced integrations.
You can configure SSL for n8n by setting up an SSL certificate in your environment, using Let’s Encrypt or another provider. When using Docker, make sure to include the certificate configuration in your docker-compose.yml
file and specify your domain and SSL email in the .env
file.
Leave a Reply