Self-Hosting n8n
Let's walk through the steps to get n8n up and running on an Ubuntu server, plus some pro tips for hosting on AWS.
Ready to take full control of your automation workflows? Self-hosting n8n is a fantastic way to do that, and Oracle Cloud offers a generous "Always Free" tier perfect for getting started. Let's walk through the steps to get n8n up and running on an Ubuntu server, plus some pro tips for hosting on AWS.
Self-Hosting n8n on Oracle Cloud with Ubuntu
The core of this guide is using Docker and Docker Compose, which simplifies the entire process. Docker containers package up everything you need to run an application, so you don't have to worry about individual dependencies.
Step 1: Create Your Oracle Cloud Instance
First, you'll need an Oracle Cloud account. The free tier is what we're after, as it provides a robust virtual machine (VM) with ample resources for n8n.
-
Log in to your Oracle Cloud Infrastructure (OCI) console.
-
Navigate to Compute > Instances and click Create Instance.
-
Choose a descriptive name for your instance.
-
For the image, select Canonical Ubuntu (the latest LTS version, like 22.04).
-
Under Shape, choose the Ampere architecture and select the VM.Standard.A1.Flex shape. You can allocate a good amount of CPU and RAM here (e.g., 2 OCPUs and 12 GB RAM) while staying within the free tier limits.
-
Ensure "Assign a public IP address" is checked. Note this down; you'll need it later.
-
Add your SSH key pair. If you don't have one, the console can generate it for you. Download the private key and store it securely.
Step 2: Configure Oracle Cloud Firewall Rules
Even with an in-server firewall like UFW, OCI's own network security groups (NSGs) act as an outer layer of defense. You need to open ports to allow traffic to your server.
-
Go to Networking > Virtual Cloud Networks (VCNs) in your OCI console.
-
Select the VCN your instance is in.
-
Click on the Security Lists or Network Security Groups associated with your instance.
-
Add Ingress Rules for the following ports:
-
Port 22 (SSH): Source CIDR
0.0.0.0/0(or your specific IP for better security). This is essential for remote access. -
Port 80 (HTTP): Source CIDR
0.0.0.0/0. -
Port 443 (HTTPS): Source CIDR
0.0.0.0/0. This is crucial for securing your n8n instance.
-
Step 3: Initial Server Setup and Docker Installation
Now it's time to connect to your new server and get it ready for n8n.
-
Open your terminal and connect via SSH using the private key you downloaded:
ssh -i /path/to/your/private_key.key ubuntu@<your_instance_public_ip>
-
Once connected, update your system packages:
sudo apt update && sudo apt upgrade -y
-
Install Docker and Docker Compose. This is the recommended way to run n8n for production.
-
Add your user to the Docker group to run commands without sudo:
sudo usermod -aG docker ubuntu
You'll need to log out and log back in for this to take effect.
-
Set up the Ubuntu firewall (UFW) to only allow necessary ports:
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Step 4: Deploy n8n with Docker Compose
Using a docker-compose.yml file makes managing n8n and its dependencies a breeze.
-
Create a directory for your n8n project:
mkdir ~/n8n && cd ~/n8n
-
Create a docker-compose.yml file using a text editor like nano:
nano docker-compose.yml
-
Paste in a basic configuration. For a production setup, it's highly recommended to use a persistent database like PostgreSQL instead of the default SQLite. Here's a minimal example:
YAML
version: '3.7' services: n8n: image: n8nio/n8n:latest restart: always ports: - "5678:5678" volumes: - n8n_data:/home/node/.n8n environment: # Optional: Configure the base URL for n8n # - N8N_HOST=n8n.yourdomain.com # - N8N_PROTOCOL=https # - WEBHOOK_TUNNEL_URL=https://n8n.yourdomain.com/ - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=db - DB_POSTGRESDB_DATABASE=n8n - DB_POSTGRESDB_USER=n8nuser - DB_POSTGRESDB_PASSWORD=your_secure_password db: image: postgres:14 restart: always environment: - POSTGRES_USER=n8nuser - POSTGRES_PASSWORD=your_secure_password - POSTGRES_DB=n8n volumes: - postgres_data:/var/lib/postgresql/data volumes: n8n_data: postgres_data:Important: Replace
your_secure_passwordwith a strong, unique password. -
Save and close the file (
Ctrl+X, thenY, thenEnterin nano). -
Launch your n8n instance:
docker compose up -d
Docker will pull the necessary images and start your containers in the background. Your n8n instance should now be accessible at http://<your_instance_public_ip>:5678.
Tips for AWS Ubuntu Hosting
AWS is another fantastic option, but it has a different set of security practices and services.
-
Security Groups are your Firewall: On AWS, a Security Group is the equivalent of a firewall for your instance. Just like with Oracle, you must explicitly open inbound ports for SSH (22), HTTP (80), and HTTPS (443) to allow traffic in. This is a critical first step.
-
Static IP with Elastic IP: When you spin up an EC2 instance, its public IP can change if you stop and start it. To avoid this, allocate and attach an Elastic IP address to your instance. It's a static IP that won't change, which is essential for consistent DNS records.
-
DNS with Route 53: If you have a custom domain name, use AWS Route 53 to manage your DNS records. You'll create an
A recordthat points your domain or a subdomain (e.g.,n8n.yourdomain.com) to the Elastic IP of your EC2 instance. -
Use Docker Compose: The same Docker Compose setup for n8n works seamlessly on AWS. It's the most reliable and portable way to run the application on any Ubuntu server.
-
Mind the Free Tier Limits: AWS offers a Free Tier for 12 months, including 750 hours of a
t2.microort3.microEC2 instance. This is more than enough for a single n8n instance for a year. Just remember that if you run more than one instance, your hours will double, and you might incur charges.
This guide is designed to get you started on a solid foundation. Once you're up and running, consider adding a reverse proxy like Nginx or Caddy to manage SSL certificates and make your setup even more secure and professional.


