Introduction
n8n is a powerful open-source workflow automation tool that allows you to connect various apps and automate tasks without writing extensive code. Self-hosting n8n on a VPS, particularly through DigitalOcean, provides better control, customization, and security for your automation workflows. In this guide, we will walk through the process of installing n8n on DigitalOcean, ensuring your self-hosted instance runs smoothly.
Prerequisites
Before diving into the installation process, ensure you have the following:
- A DigitalOcean account (sign up here).
- Basic knowledge of Linux command line.
- A VPS with at least 1GB RAM (recommended for optimal performance).
- A domain name (optional but encouraged for easier access).
Cost Comparison of Recommended VPS Providers
| Provider | Price (Monthly) | Features |
|---|---|---|
| DigitalOcean | 6 USD | Simple API, data center locations |
| Contabo VPS | 5.99 EUR/mo | High storage, affordable pricing |
| Hetzner Cloud | 4.15 EUR/mo | European data centers, flexible |
| Vultr | 6 USD | High performance, multiple OS types |
| Linode (Akamai) | 5 USD | Fast SSD, 99.99% uptime guarantee |
You can explore further options in our full VPS comparison.
Step-by-Step Installation of n8n on DigitalOcean
Step 1: Create a Droplet
- Log in to your DigitalOcean account.
- Click on the โCreateโ button in the upper right corner and select โDroplets.โ
- Choose an OS image. We recommend Ubuntu 20.04 LTS.
- Pick a plan based on your needs (the Basic Droplet with 1GB RAM is usually sufficient).
- Select a data center region close to your target audience.
- Set up authentication (use SSH keys for security).
- Finalize your droplet settings and click โCreate Droplet.โ
Step 2: Connect to Your Droplet
Use SSH to connect to your newly created droplet:
ssh root@your_droplet_IP_address
Replace your_droplet_IP_address with the actual IP address of your droplet.
Step 3: Install Node.js and npm
n8n requires Node.js; install it using the following commands:
sudo apt update
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
Step 4: Install n8n
Once Node.js is installed, install n8n globally using npm:
sudo npm install n8n -g
Step 5: Run n8n
You can start n8n directly in the terminal with:
n8n
By default, n8n runs on port 5678. To access it, navigate to http://your_droplet_IP_address:5678 in your browser.
Step 6: Set Up n8n to Run in the Background
To keep n8n running even when the terminal is closed, you can use screen or pm2. Hereโs how to do it with pm2:
-
Install pm2:
sudo npm install pm2 -g -
Start n8n using pm2:
pm2 start n8n pm2 save pm2 startup
Step 7: Configure Reverse Proxy (Optional)
For better security and management, configure a reverse proxy using Nginx:
-
Install Nginx:
sudo apt install nginx -
Create a new configuration file:
sudo nano /etc/nginx/sites-available/n8n -
Insert the following configuration:
server { listen 80; server_name your_domain_or_ip; location / { proxy_pass http://localhost:5678; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } -
Enable the configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/ sudo systemctl restart nginx
Access n8n using http://your_domain_or_ip.
FAQs
How can I secure my n8n installation on DigitalOcean?
Securing your n8n installation involves several steps. First, always use HTTPS by configuring SSL certificates. You can use Letโs Encrypt to obtain free SSL certificates. Second, protect your n8n instance with basic authentication. Finally, regularly update your n8n version to incorporate security patches and improvements.
Is it necessary to have a domain name to run n8n on DigitalOcean?
While itโs not strictly necessary to have a domain name to run n8n on DigitalOcean, it is highly recommended. Using a domain makes it easier to access your n8n instance and is more user-friendly than using an IP address. Additionally, a domain name helps in securing your application with an SSL certificate, which is essential for a production environment.
Can I run n8n on other VPS providers?
Yes, n8n can be installed on any VPS provider that supports Node.js. This includes providers like Contabo, Hetzner Cloud, Vultr, and Linode. Follow similar steps as outlined above, ensuring your VPS has sufficient resources. Always refer to the documentation for specific configurations based on the provider.
Conclusion
Self-hosting n8n on DigitalOcean is a straightforward process, enabling you to leverage powerful workflow automation tools in your projects. With the steps outlined above, you can quickly get your n8n instance running and start defining your workflows. Donโt forget to explore other VPS options if DigitalOcean isnโt your top choice, and have fun automating!