Skip to content

Instantly share code, notes, and snippets.

@Muminur
Created October 26, 2025 07:20
Show Gist options
  • Select an option

  • Save Muminur/562a2dad6847c62654a71be3fef62f53 to your computer and use it in GitHub Desktop.

Select an option

Save Muminur/562a2dad6847c62654a71be3fef62f53 to your computer and use it in GitHub Desktop.
Install N8N on Ubuntu VPS 22.04
# Check if Docker is already installed
docker --version
# If not installed, install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Start Docker
sudo systemctl start docker
sudo systemctl enable docker
# Verify Docker is running
sudo docker ps
# Create n8n directory
mkdir -p ~/n8n
cd ~/n8n
# Fix permissions on the data directory
# The n8n container runs as user 'node' with UID 1000
sudo chown -R 1000:1000 ./data
mkdir -p data
sudo chown -R 1000:1000 data
sudo chmod -R 755 data
# Create docker-compose.yml
cat > docker-compose.yml << 'EOF'
services:
n8n:
image: n8nio/n8n
container_name: n8n
restart: always
user: "1000:1000"
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=ChangeThisPassword123!
- N8N_HOST=0.0.0.0
- N8N_PORT=5678
- N8N_PROTOCOL=http
- NODE_ENV=production
- WEBHOOK_URL=http://74.208.132.120:5678/
- GENERIC_TIMEZONE=Asia/Dhaka
- TZ=Asia/Dhaka
- DB_SQLITE_POOL_SIZE=3
- N8N_RUNNERS_ENABLED=true
- N8N_BLOCK_ENV_ACCESS_IN_NODE=false
- N8N_GIT_NODE_DISABLE_BARE_REPOS=true
volumes:
- ./data:/home/node/.n8n
EOF
# Start n8n
sudo docker compose up -d
# View logs
sudo docker compose logs -f
You should now see n8n starting up successfully without permission errors or warnings. The logs should show something like:
```
n8n | Editor is now accessible via:
n8n | http://0.0.0.0:5678/
Once it's running, you can access n8n at http://your-server-ip:5678 with:
Username: admin
Password: ChangeThisPassword123!
#DEBUG Commands, Skip if running fine
.............................................................................................
# Check if UFW is active
sudo ufw status
# If UFW is active, allow port 5678
sudo ufw allow 5678/tcp
# Or check iptables
sudo iptables -L -n | grep 5678
# Check if n8n container is running
docker ps
# Check if port 5678 is listening
netstat -tulpn | grep 5678
# OR
ss -tulpn | grep 5678
# Check UFW status
sudo ufw status
# Allow port 5678
sudo ufw allow 5678/tcp
# Reload UFW
sudo ufw reload
# Verify the rule was added
sudo ufw status numbered
# Check current iptables rules ||||||| Check iptables (if UFW isn't active)
sudo iptables -L -n
# Allow port 5678
sudo iptables -A INPUT -p tcp --dport 5678 -j ACCEPT
# Save iptables rules
sudo netfilter-persistent save
# OR
sudo iptables-save > /etc/iptables/rules.v4
VPS Firewall (Cloud Panel)
Since you're using VPS, you may also need to allow port 5678 in the Cloud Panel:
Log in to your account
Go to your VPS management panel
Find Firewall or Security settings
Add a rule to allow TCP port 5678 from all sources (0.0.0.0/0)
.............................................................................................
OPTIONAL: Use Nginx Reverse Proxy on Port 80
# Install Nginx
sudo apt update
sudo apt install nginx -y
# Create Nginx configuration
sudo nano /etc/nginx/sites-available/n8n
Add this configuration: Give just IP replacing YOUR_SERVER_IP x.x.x.x like this
server {
listen 80;
server_name YOUR_SERVER_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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# Enable the site
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
# Remove default site if it conflicts
sudo rm /etc/nginx/sites-enabled/default
# Test Nginx configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
# Make sure port 80 is allowed
sudo ufw allow 80/tcp
Then access n8n at: http://YOURSERVERIP (no port needed), NOW it will use port 80
Production Setup with SSL/HTTPS (Recommended)
Production Setup with SSL/HTTPS (Recommended)
If you have a domain name, let's set up proper HTTPS:
Step 1: Point Domain to Your Server
First, create an A record for your domain pointing to 74.208.132.120
Example: n8n.yourdomain.com → 74.208.132.120
Step 2: Install Nginx and Certbot
bash# Install Nginx and Certbot
sudo apt update
sudo apt install nginx certbot python3-certbot-nginx -y
Step 3: Create Nginx Configuration
bash# Create Nginx config (replace n8n.yourdomain.com with your actual domain)
sudo nano /etc/nginx/sites-available/n8n
Add this configuration:
nginxserver {
listen 80;
server_name n8n.yourdomain.com;
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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
bash# Enable the site
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
# Test Nginx configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
# Allow HTTP and HTTPS in firewall
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Step 4: Get SSL Certificate
bash# Get SSL certificate (replace with your domain)
sudo certbot --nginx -d n8n.yourdomain.com
Step 5: Update n8n Configuration for HTTPS
cd ~/n8n
cat > docker-compose.yml << 'EOF'
services:
n8n:
image: n8nio/n8n
container_name: n8n
restart: always
user: "1000:1000"
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=ChangeThisPassword123!
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://n8n.yourdomain.com/
- GENERIC_TIMEZONE=Asia/Dhaka
- TZ=Asia/Dhaka
- DB_SQLITE_POOL_SIZE=3
- N8N_RUNNERS_ENABLED=true
- N8N_BLOCK_ENV_ACCESS_IN_NODE=false
- N8N_GIT_NODE_DISABLE_BARE_REPOS=true
volumes:
- ./data:/home/node/.n8n
EOF
# Restart n8n
docker compose down
docker compose up -d
Now access n8n at: https://n8n.yourdomain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment