This guide walks you through setting up n8n on a Linux VPS using Docker, Docker Compose, and Traefik for SSL termination.
- A Linux VPS (Ubuntu/Debian recommended)
- SSH access to your VPS with sudo privileges
- A domain name pointing to your VPS
- Basic familiarity with command line
Before installing n8n, you'll need to set up a DNS record for your domain:
-
Get your server's public IP.
-
In your domain's DNS settings:
- Create an A record with:
- Host: The subdomain you plan to use (e.g.,
n8n) - Value: Server's IP address
- TTL: 3600 (default)
- Host: The subdomain you plan to use (e.g.,
- Create an A record with:
-
Verify setup (may take up to 1 hour):
dig +short subdomain.yourdomain.com # Should return your IP
Example: To make n8n accessible at n8n.example.com, create an A record for n8n pointing to your server IP.
Go to your terminal and generate a public and private key. Add the public key to your VPS provider.
ssh-keygen -t rsa -b 4096
ssh root@server_ipDownload the installation script directly from GitHub, make the script executable and execute the script:
curl -sSL https://raw.githubusercontent.com/dennisrongo/n8n-scripts/refs/heads/master/n8n-install.sh -o n8n-install.sh && chmod +x n8n-install.sh && ./n8n-install.shcurl -sSL https://raw.githubusercontent.com/dennisrongo/n8n-scripts/refs/heads/master/n8n-pg-install.sh -o n8n-postgres-install.sh && chmod +x n8n-postgres-install.sh && ./n8n-postgres-install.shThe script will:
- Install Docker and Docker Compose
- Create a project directory at
~/n8n-traefik - Set up the necessary configuration files
- Create Docker volumes for data persistence
- Prompt you to edit the
.envfile - Offer to start the containers
When prompted, edit your .env file with the following information:
DOMAIN_NAME: Your actual domain (e.g.,yourdomain.com)SUBDOMAIN: The subdomain for n8n that you set up in Step 1 (e.g.,n8n)SSL_EMAIL: Your email address for SSL certificate registrationGENERIC_TIMEZONE: Your preferred timezone
Example configuration:
DOMAIN_NAME=yourdomain.com
SUBDOMAIN=n8n
SSL_EMAIL=your-email@example.com
GENERIC_TIMEZONE=UTC
This would make n8n accessible at https://n8n.yourdomain.com.
If you didn't start the service during the script execution, you can start it manually:
cd ~/n8n-traefik
sudo docker-compose up -dThe -d flag runs the containers in detached mode (background).
- Check if the containers are running:
sudo docker-compose ps- View the logs:
sudo docker-compose logs -f- Access n8n in your web browser at
https://n8n.yourdomain.com(replace with your actual domain).
cd ~/n8n-traefik
sudo docker-compose downcd ~/n8n-traefik
sudo docker-compose restartcd ~/n8n-traefik
sudo docker-compose pull
sudo docker-compose down
sudo docker-compose up -dThe data is stored in a Docker volume. To back it up:
sudo docker run --rm -v n8n_data:/source -v $(pwd):/backup alpine tar -czf /backup/n8n-backup.tar.gz -C /source .This creates a backup file n8n-backup.tar.gz in your current directory.
sudo docker-compose pssudo docker-compose logs -fIf you have SSL certificate issues:
- Make sure your domain is properly pointing to your VPS IP address
- Check the Traefik logs for certificate-related errors:
sudo docker-compose logs traefikIf your server reboots, the Docker containers should restart automatically (due to restart: always in the compose file). If they don't:
cd ~/n8n-traefik
sudo docker-compose up -d- The n8n admin interface is publicly accessible. Consider setting up authentication.
- Review and customize the Traefik configuration for your security requirements.
- Keep your server and Docker images updated.
For reference, the installation script performs the following tasks:
- Installs Docker and Docker Compose
- Creates configuration files (docker-compose.yaml and .env)
- Sets up Docker volumes for data persistence
- Guides you through configuration and startup
If you need to completely remove n8n and all associated data:
# Stop and remove containers
cd ~/n8n-traefik
sudo docker-compose down
# Remove the Docker volumes
sudo docker volume rm n8n_data traefik_data
# Remove Docker images (optional)
sudo docker rmi docker.n8n.io/n8nio/n8n traefik
# Remove the installation directory
cd ~
rm -rf ~/n8n-traefikWarning: This will permanently delete all your n8n workflows, credentials, and configurations. Make sure to back up any important data before proceeding.
This installation script and guide were created by Dennis from Lean Code Automation.
By following this guide, you should have a working n8n installation with automatic HTTPS support through Traefik. Happy automating!