How to Self-Host n8n with a VPS and Docker
This guide is for technical operators and engineers looking to deploy n8n on their own infrastructure. Get practical steps to set up and manage your n8n instance securely and privately.
To self-host n8n with a VPS and Docker, provision a virtual private server, install Docker and Docker Compose, then use a `docker-compose.yml` file to define your n8n service. Configure a reverse proxy like Nginx or Caddy for SSL and domain access. This setup offers full control over your automation workflows and data, suitable for technical operators managing their own infrastructure.
Why Self-Host n8n?
Self-hosting n8n gives you complete control over your automation workflows and data. Instead of relying on a third-party cloud service, your n8n instance runs on hardware you manage, often leading to better data privacy and customisation options. While the managed cloud version of n8n is convenient, self-hosting offers cost efficiency for specific use cases and the flexibility to integrate with internal systems directly. It's a solid choice for those who need fine-grained control over their automation infrastructure.
Prerequisites: What You'll Need
Before you begin, ensure you have a Virtual Private Server (VPS) running a Linux distribution, such as Ubuntu. You'll also need a domain name pointed to your VPS's IP address and a basic understanding of the Linux command line. Make sure Docker and Docker Compose are installed on your VPS. Most VPS providers offer straightforward guides for installing these. A fresh VPS instance is recommended to avoid conflicts with existing services, simplifying the setup process considerably.
Setting Up n8n with Docker Compose
The most reliable way to deploy n8n on a VPS is using Docker Compose. Create a `docker-compose.yml` file on your server. This file defines the n8n service, its environment variables (like `N8N_HOST`, `N8N_PROTOCOL`), and persistent storage volumes for your workflow data. This setup ensures n8n runs in an isolated environment, making updates and migrations simpler. Remember to set strong credentials and secure your n8n instance from the outset.
Configuring a Reverse Proxy and SSL
For secure access to your n8n instance via your domain, you'll need a reverse proxy. Nginx or Caddy are common choices. The reverse proxy will listen on standard web ports (80 and 443), forward requests to your n8n Docker container, and handle SSL termination. Tools like Certbot can automate the process of obtaining and renewing free SSL certificates from Let's Encrypt, ensuring all traffic to your n8n instance is encrypted. This is a critical security step.
Maintenance and Updates
Regular maintenance is vital for a self-hosted n8n instance. Keep your VPS operating system, Docker, and n8n up to date. For n8n, this typically involves running `docker-compose pull` to fetch the latest image, followed by `docker-compose up -d` to restart the container with the new version. Always back up your n8n data volume before major updates. Monitor your VPS resources to ensure n8n has enough memory and CPU, especially as your number of workflows grows.
Frequently Asked
What are the typical costs of self-hosting n8n?
+
Costs primarily involve your VPS provider. Basic VPS plans can start from around £5-£10 per month, depending on specifications. You'll also need to factor in domain registration costs, which are usually annual. Compared to some cloud services, self-hosting can be more cost-effective for long-term, consistent usage, especially if you have existing VPS infrastructure.
What are the main benefits of self-hosting n8n?
+
The key benefits are enhanced data privacy, full control over your infrastructure, and greater customisation. You decide where your data resides and how it's handled. It also allows for deeper integration with internal systems and can be more budget-friendly than managed services over time, particularly for high-volume or specific use cases.
Which VPS providers are recommended for n8n?
+
Popular and reliable VPS providers include DigitalOcean, Vultr, and Hetzner. They offer good performance, clear pricing, and straightforward setup processes for Linux instances. Choose a provider that offers a data centre location close to your users or integrated services for optimal latency and compliance.
How do I update my self-hosted n8n instance?
+
To update n8n, navigate to your `docker-compose.yml` directory on the VPS. Then, run `docker-compose pull` to download the latest n8n Docker image. After the pull completes, execute `docker-compose up -d` to stop the old container and start a new one with the updated image. Always back up your data volume beforehand.
What security considerations should I keep in mind?
+
Implement a firewall (e.g., UFW) on your VPS, only allowing necessary ports (22, 80, 443). Use strong, unique passwords and SSH keys. Keep your operating system, Docker, and n8n updated. Ensure your reverse proxy correctly handles SSL certificates. Regularly review n8n's access logs and consider enabling two-factor authentication if available for your setup.
Ready to Build Custom Automations?
Book a free discovery call with Agentized to explore how bespoke AI agents and RAG systems can enhance your operations. We use tools like n8n daily.