Self-Host n8n: Easy Setup on Hetzner Cloud
Learn how to install and run your own n8n instance on a Hetzner cloud server. This step-by-step guide covers everything from server setup to accessing your new n8n installation.
Step-by-Step Guide: Installing n8n on a Hetzner Server
Are you looking to self-host n8n, the workflow automation tool? In this guide, we'll walk you through the process of setting up n8n on a Hetzner cloud server. This setup uses Docker and Caddy as a reverse proxy, providing you with a robust and secure installation.
Required time: 5 minutes
Prerequisites
Before we begin, make sure you have:
1. A Hetzner Cloud account
2. Basic knowledge of terminal/command-line operations
3. An SSH key pair on your local machine
Step 1: Create a Hetzner Server
1. Log in to the Hetzner Cloud Console.
2. Click on "Add Server" or "Create Server".
3. Choose the region closest to you (e.g., Helsinki).
4. Under "Image", select the "Apps" tab and choose "Docker CE".
5. For the server type, consider selecting an ARM64 server, which is often cheaper and more powerful than x86 servers.
6. Add your SSH public key to the server configuration.
7. Review your choices and click "Create & Buy Now".
Step 2: Connect to Your Server
Once your server is created, connect to it via SSH:
ssh root@your_server_ip
Replace `your_server_ip` with the IP address provided by Hetzner.
Step 3: Update System and Install Docker Compose
Update your system and install Docker Compose:
apt update && apt -y upgrade
apt install docker-compose-plugin
Step 4: Clone the n8n Docker Configuration
Clone the n8n Docker configuration repository:
git clone https://github.com/n8n-io/n8n-docker-caddy.git
cd n8n-docker-caddy
Step 5: Create Docker Volumes
Create Docker volumes for Caddy and n8n data:
docker volume create caddy_data
sudo docker volume create n8n_data
Step 6: Configure DNS
Create an A record for your chosen subdomain (e.g., n8n.yourdomain.com) pointing to your server's IP address.
Step 7: Open Firewall Ports
Allow incoming traffic on ports 80 and 443:
sudo ufw allow 80
sudo ufw allow 443
Step 8: Configure n8n
Edit the `.env` file to set your environment variables:
nano .env
Update the placeholders with your actual values (e.g., domain, email, username, password).
Step 9: Configure Caddy
Edit the Caddy configuration file:
nano caddy_config/Caddyfile
Replace the placeholder domain with your actual domain (e.g., n8n.yourdomain.com).
Step 10: Start n8n and Caddy
Launch n8n and Caddy using Docker Compose:
docker compose up -d
Step 11: Access n8n
Open your browser and navigate to your n8n subdomain (e.g., https://n8n.yourdomain.com). Log in using the credentials you set in the `.env` file.
Maintenance and Updates
To stop n8n and Caddy:
sudo docker compose stop
To update n8n:
docker compose pull
docker compose down
docker compose up -d
Conclusion
Congratulations! You've successfully installed n8n on your Hetzner server. Remember to keep your installation updated and secure. If you encounter any issues, consult the n8n documentation or community forums for assistance.