Key Concepts
Self-hosting N8N, VPS (Virtual Private Server), Docker, Docker Compose, npm packages, SSH, Digital Ocean, Subdomain, DNS, Caddy, Environment Variables, Docker Volumes, N8N Instance Management (Upgrades, Troubleshooting).
Self-Hosting N8N: An Overview
The video explains how to self-host N8N, an open-source workflow automation platform, as an alternative to using N8N's hosted service. Self-hosting offers cost savings, better data control, improved privacy, and customization options like installing custom npm packages.
Why Self-Host N8N?
- Cost Savings: Self-hosting eliminates monthly subscription fees associated with the hosted N8N service. While a VPS incurs costs, it's generally cheaper, especially for multiple instances.
- Data Control: Self-hosting gives you complete control over your data, preventing account shutdowns and enhancing privacy, crucial for sensitive industries like healthcare.
- Customization: Self-hosting allows installing any npm package, expanding workflow capabilities.
Hosting N8N on Your Laptop (Local Installation)
This method is suitable for simple workflows and avoids VPS costs.
Step-by-Step Process:
- Install Docker: Download and install Docker Desktop from the official Docker website.
- Download N8N Docker Image: Open a terminal and run
docker pull n8nio/n8n. - Run N8N Container: Execute
docker run -d -p 5678:5678 --name n8n n8nio/n8n. The-dflag runs the container in detached mode,-pmaps port 5678, and--nameassigns a name to the container. - Access N8N: Open a web browser and navigate to
http://localhost:5678. - Create Admin Account: Follow the on-screen instructions to create an admin account.
- Stop N8N: Press
Ctrl+Cin the terminal to stop the container.
Downsides of Local Installation:
- OAUTH Issues: Difficulties with OAUTH-based APIs (e.g., Google APIs) due to the inability to receive requests from the internet. N8N's tunnel service is mentioned as a potential but unreliable workaround.
- Uptime Limitations: Workflows cannot run 24/7 as the laptop needs to be constantly running.
Hosting N8N on a VPS (Virtual Private Server)
A VPS provides a server that runs 24/7, suitable for professional use. Digital Ocean is recommended for beginners due to its pre-built N8N droplets.
Using Digital Ocean's Pre-Built N8N Droplet:
- Create a Digital Ocean Account: Sign up on the Digital Ocean website.
- Create a Droplet: In the dashboard, go to the "Droplets" menu and click "Create Droplet."
- Choose N8N Droplet: In the "Choose an image" section, go to the "Marketplace" tab and select the N8N droplet. Note that this is a third-party image.
- Select Plan: Choose a CPU, memory, and storage package. Start with the lowest package and upgrade later if needed.
- Authentication: Choose SSH keys for secure connection. Follow the instructions to generate and add your SSH public key.
- Create Droplet: Click "Create Droplet."
- Configure DNS: Point a subdomain to the droplet's IP address by adding an A record in your DNS editor.
- Connect via SSH: Use the command
ssh root@your_droplet_ipto connect to the droplet. - Initial Setup: Follow the on-screen instructions to configure the subdomain and domain name.
- Access N8N: Access N8N in your browser using the configured subdomain and create your admin account.
Installing N8N on a VPS with Ubuntu (Manual Installation)
This method offers more flexibility and allows using any hosting provider.
Step-by-Step Process:
- Create a Digital Ocean Droplet: Choose Ubuntu as the operating system and select a basic shared CPU plan.
- Connect via SSH: Use the command
ssh root@your_droplet_ipto connect to the droplet. - Create a New User: Create a new user (e.g., "n8n") using
adduser n8nand grant sudo privileges usingusermod -aG sudo n8n. - Switch to the New User: Switch to the new user's home directory using
sudo su - n8n. - Clone N8N Setup Repository: Clone the N8N setup repository using
git clone https://github.com/n8n-io/n8n-docker.git. - Navigate to the Directory:
cd n8n-docker - Install Docker: Follow the official Docker installation instructions for Ubuntu.
- Create Docker Volumes: Create Docker volumes for Caddy and N8N data using
docker volume create n8n_caddy_dataanddocker volume create n8n_data. - Configure DNS: Point a subdomain to the droplet's IP address by adding an A record in your DNS editor.
- Configure Environment Variables: Edit the
.envfile using a text editor (e.g.,vim .env) to customize the data folder, domain name, and subdomain. - Configure Caddy: Edit the
Caddyfilein thecaddy/configfolder to replace the placeholder with your subdomain. - Start Docker Compose: Start the N8N instance using
docker-compose up -d. - Access N8N: Access N8N in your browser using the configured subdomain and create your admin account.
Managing Your N8N Instance
Troubleshooting:
- If N8N crashes, Docker should restart it automatically.
- If the issue persists, SSH into the server, stop the container using
docker stop n8n, and restart it usingdocker start n8n.
Upgrading N8N:
- Check for new version message in the N8N menu bar.
- Download the latest N8N Docker image.
- Stop the container.
- Restart the container.
Installing Custom npm Packages:
-
SSH into the server and stop the N8N instance.
-
Create a
Dockerfilewith the following structure:FROM n8nio/n8n USER root RUN npm install cheerio # Replace cheerio with your desired package(s) USER nodeIf you want to install multiple packages:
FROM n8nio/n8n USER root RUN npm install cheerio request USER node -
Modify the
docker-compose.ymlfile to use the custom Dockerfile:version: "3.7" services: n8n: build: context: . dockerfile: Dockerfile image: n8n-custom # Local name for the container restart: always ports: - "5678:5678" environment: - NODE_ENV=production - N8N_BASIC_AUTH_ACTIVE=true - N8N_BASIC_AUTH_USER - N8N_BASIC_AUTH_PASSWORD - NODE_FUNCTION_ALLOW_EXTERNAL=cheerio # Add the package name here volumes: - n8n_data:/home/node/.n8n -
Add the
NODE_FUNCTION_ALLOW_EXTERNALvariable to the.envfile, listing the npm packages separated by commas (e.g.,NODE_FUNCTION_ALLOW_EXTERNAL=cheerio,request). -
Restart the N8N instance using
docker-compose up -d.
Conclusion
Self-hosting N8N provides significant advantages in terms of cost, data control, and customization. The video details the steps for installing N8N both locally using Docker and on a VPS, with a focus on Digital Ocean. It also covers essential management tasks like troubleshooting, upgrading, and installing custom npm packages, empowering users to leverage the full potential of N8N for their automation needs. The speaker also promotes his AI automation agency, encouraging business owners to inquire about AI and automation solutions.
AI summaries can miss context or contain errors. Check important details against the original video.