Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created January 1, 2025 07:11
Show Gist options
  • Save alnutile/01db5ca138281750c2b2f5739f2258c1 to your computer and use it in GitHub Desktop.
Save alnutile/01db5ca138281750c2b2f5739f2258c1 to your computer and use it in GitHub Desktop.
All the install notes from Claude

N8N Running on Main Server

Here's a comprehensive README for setting up n8n on Ubuntu with Nginx:

n8n Server Setup Guide

Prerequisites

  • Ubuntu Server
  • Node.js >= 18.17
  • Nginx
  • Domain name pointed to your server

Step 1: Install Node.js using NVM

# Install NVM
curl -o- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh> | bash

# Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh"

# Install Node.js
nvm install 18.19.0
nvm use 18.19.0

Step 2: Install n8n

npm install n8n -g
mkdir ~/.n8n

Step 3: Create Systemd Service

Create file at /etc/systemd/system/n8n.service:

[Unit]
Description=n8n
After=network.target

[Service]
Type=simple
User=forge
Environment="PATH=/home/forge/.nvm/versions/node/v18.19.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Environment="NODE_VERSION=18.19.0"
Environment="N8N_PORT=5678"
Environment="N8N_HOST=your-domain.com"
Environment="N8N_PROTOCOL=https"
Environment="N8N_WEBHOOK_URL=https://your-domain.com"
Environment="WEBHOOK_URL=https://your-domain.com"
Environment="N8N_PATH=/"
Environment="N8N_EDITOR_BASE_URL=https://your-domain.com"
Environment="NODE_FUNCTION_ALLOW_EXTERNAL=pdf-lib"
Environment="N8N_WEBHOOK_TEST_URL=https://your-domain.com"
Environment="N8N_WEBHOOK_TUNNEL_URL=https://your-domain.com"
Environment="NODE_OPTIONS=--max-old-space-size=4096"
Environment="NODE_FUNCTION_ALLOW_BUILTIN=uuid,fs,path,child_process"
Environment="N8N_CORS_ENABLE=true"
Environment="N8N_CORS_ALLOWED_ORIGINS=https://*.your-domain.com,<http://localhost:3000>,<http://localhost:5174>,<http://localhost:5173>"
Environment="N8N_CORS_METHODS=GET,POST,OPTIONS,HEAD,PATCH"
Environment="N8N_CORS_ALLOW_CREDENTIALS=true"
Environment="N8N_CORS_ALLOW_HEADERS=content-type,authorization,referrer-policy,sec-ch-ua,sec-ch-ua-mobile,sec-ch-ua-platform"
Environment="N8N_CORS_EXPOSE_HEADERS=content-type,authorization"
Environment="NODE_ENV=production"
Environment="N8N_WEBHOOK_TIMEOUT=600000"
Environment="N8N_EXECUTIONS_TIMEOUT=600"
Environment="N8N_PROCESS_TIMEOUT=600"
ExecStart=/home/forge/.nvm/versions/node/v18.19.0/bin/n8n start
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Step 4: Setup Nginx Configuration

Create file at /etc/nginx/sites-available/your-domain.com:

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.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_buffering off;
        proxy_cache off;
        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;

        # WebSocket support
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        # Extended timeouts
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
        proxy_read_timeout 300;
        send_timeout 300;
        keepalive_timeout 300;
    }
}

Step 5: Enable Site and Setup SSL

# Create symlink
sudo ln -s /etc/nginx/sites-available/your-domain.com /etc/nginx/sites-enabled/

# Test nginx config
sudo nginx -t

# Install Certbot
sudo apt install certbot python3-certbot-nginx

# Get SSL certificate
sudo certbot --nginx -d your-domain.com

Step 6: Start Services

# Enable and start n8n
sudo systemctl enable n8n
sudo systemctl start n8n

# Reload nginx
sudo systemctl reload nginx

Useful Commands

# Check n8n status
sudo systemctl status n8n

# View n8n logs
sudo journalctl -u n8n.service -f

# Restart n8n
sudo systemctl restart n8n

# Test nginx config
sudo nginx -t

# Reload nginx
sudo systemctl reload nginx

Important Notes

  • Replace your-domain.com with your actual domain
  • Adjust the Node.js path if using a different version
  • Modify CORS settings according to your needs
  • The NODE_FUNCTION_ALLOW_BUILTIN and NODE_FUNCTION_ALLOW_EXTERNAL settings allow specific Node.js modules to be used in n8n functions
  • The memory limit is set to 4GB (-max-old-space-size=4096); adjust according to your server's capacity

Security Considerations

  • Always use HTTPS in production
  • Review and adjust CORS settings based on your requirements
  • Keep Node.js and n8n updated to the latest stable versions
  • Regularly backup your n8n data
  • Monitor server resources and logs

Would you like me to explain or expand on any part of this documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment