This guide walks you through deploying n8n, a workflow automation tool, on your own virtual private server (VPS) using Docker Compose, and then connecting it to a custom domain with HTTPS. By the end, you’ll have a self-hosted n8n instance that you can access at your own domain, with automatic SSL certificates, and that runs as a background service.
What You’ll Need
- A VPS with a public IP address (Ubuntu 22.04 or 24.04 recommended) and SSH access.
- A domain name where you can add an A record (e.g.,
n8n.example.com). - Basic comfort with the command line.
- Docker and Docker Compose installed on the server. If not installed, we’ll cover that.
Step-by-Step
-
Point your domain to the server
In your DNS provider’s dashboard, create an A record for the subdomain you want (e.g.,n8n) pointing to your VPS’s public IP address. Wait for DNS to propagate (usually a few minutes, but can take up to 24 hours). -
Connect to your VPS via SSH
Open a terminal and run:ssh user@your-server-ip. Update the system packages:sudo apt update && sudo apt upgrade -y. -
Install Docker and Docker Compose
If you don’t have them, install Docker with the official convenience script:curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh. Then install the Docker Compose plugin:sudo apt install docker-compose-plugin. Verify withdocker --versionanddocker compose version. -
Create a project directory
Run:mkdir ~/n8n && cd ~/n8n. This will hold yourdocker-compose.ymland data. -
Create the docker-compose.yml file
Use a text editor (e.g.,nano docker-compose.yml) and paste the following configuration:version: '3.8' services: n8n: image: n8nio/n8n restart: always ports: - "127.0.0.1:5678:5678" environment: - N8N_HOST=n8n.example.com - N8N_PROTOCOL=https - WEBHOOK_URL=https://n8n.example.com - GENERIC_TIMEZONE=UTC - TZ=UTC volumes: - n8n_data:/home/node/.n8n caddy: image: caddy:2 restart: always 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:Replace
n8n.example.comwith your actual domain. This setup uses Caddy as a reverse proxy that automatically obtains and renews SSL certificates. -
Create the Caddyfile
In the same directory, create a file namedCaddyfilewithnano Caddyfileand add:n8n.example.com { reverse_proxy n8n:5678 }Again, replace the domain with yours.
-
Start the services
Runsudo docker compose up -d. This will pull the images and start n8n and Caddy in the background. -
Check the logs
Runsudo docker compose logs -fto see the startup output. Wait until you see that n8n is listening and Caddy has obtained a certificate (look for “certificate obtained”). -
Access n8n
Open your browser and go tohttps://n8n.example.com. You should see the n8n setup screen. Create your admin account (email and password) and you’re ready to build workflows.
Common Mistakes
- Using the wrong domain in the config – Make sure
N8N_HOST,WEBHOOK_URL, and the Caddyfile domain all match exactly, including thehttps://where required. - Exposing n8n directly on port 5678 – Binding to
0.0.0.0:5678would bypass Caddy and leave n8n unencrypted. We bind to127.0.0.1to keep it internal. - Forgetting to open ports 80 and 443 – If your VPS has a firewall (like UFW), allow HTTP and HTTPS:
sudo ufw allow 80/tcpandsudo ufw allow 443/tcp. - Not setting a timezone – n8n uses UTC by default; if you want your workflows to use your local time, set
GENERIC_TIMEZONEandTZto your IANA timezone (e.g.,Europe/Berlin).
Tips
- Use a dedicated subdomain – Like
n8n.example.comrather than the root domain, so you can host other services later. - Back up your data – The
n8n_datavolume contains all your workflows and credentials. Regularly copy it to a safe location:sudo docker run --rm -v n8n_n8n_data:/data -v $(pwd):/backup alpine tar czf /backup/n8n-backup.tar.gz -C /data . - Keep Docker Compose updated – When you want to upgrade n8n, run
sudo docker compose pulland thensudo docker compose up -d. - Set up automatic restarts – The
restart: alwayspolicy ensures n8n and Caddy start after a reboot or crash.
Troubleshooting
- Cannot access the site – First, check that the domain resolves to your server:
dig n8n.example.com. Then verify ports are open:sudo ufw status. Check the container logs:sudo docker compose logs. - SSL certificate not issued – If you see errors like “certificate obtained” not appearing, ensure your domain points to the server and that port 80 is reachable from the internet. Sometimes DNS propagation is slow; wait and restart Caddy:
sudo docker compose restart caddy. - n8n is running but Caddy returns 502 – This usually means Caddy can’t reach n8n. Check that the
reverse_proxyline uses the service namen8n(not localhost). Also confirm that n8n is listening on port 5678 inside the container:sudo docker exec -it n8n curl localhost:5678. - Changes to docker-compose.yml don’t apply – After editing the file, run
sudo docker compose up -dagain. If you changed environment variables, you may need to recreate the container:sudo docker compose up -d --force-recreate.
Frequently Asked Questions
Do I need to install Node.js or npm?
No. The Docker image includes everything n8n needs. You only need Docker and Docker Compose on the server.
How do I update n8n to a new version?
Run sudo docker compose pull to fetch the latest image, then sudo docker compose up -d to recreate the container. Your data is preserved in the volume.
Can I use a different reverse proxy like Nginx or Traefik?
Yes, you can replace Caddy with any reverse proxy. The key is to forward HTTPS traffic to localhost:5678 and set the correct environment variables (N8N_HOST, N8N_PROTOCOL, WEBHOOK_URL).
How do I back up my n8n data?
The data is stored in the Docker volume n8n_data. You can back it up using the docker run command shown in the Tips section, or use a tool like restic to automate backups.
Why is my webhook URL not working?
Make sure the WEBHOOK_URL environment variable is set to https://yourdomain.com (no trailing slash). Also, in n8n, when you create a webhook node, the generated URL should use your custom domain.
Is it safe to expose n8n to the internet?
n8n has its own authentication, so it’s reasonably safe. However, you should use a strong password, keep the instance updated, and consider adding IP allowlisting or a VPN for extra security.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It