N8N is a powerful, open-source workflow automation tool that lets you connect different services and automate repetitive tasks. Ramnode provides reliable and affordable VPS hosting, making it an excellent choice for deploying N8N. This comprehensive guide will walk you through the entire process of setting up N8N on a Ramnode VPS.

Prerequisites

Before we begin, make sure you have:

  • A Ramnode VPS (minimum 1GB RAM, 1 CPU core recommended)
  • SSH access to your VPS
  • A domain name (optional but recommended for production use)
  • Basic knowledge of Linux command line

Step 1: Initial Server Setup

First, connect to your Ramnode VPS via SSH:

ssh root@your-server-ip

Update your system packages:

apt update && apt upgrade -y

Create a new user for better security:

adduser n8n
usermod -aG sudo n8n

Switch to the new user:

su - n8n

Step 2: Install Node.js and npm

N8N requires Node.js to run. Install Node.js using NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

Verify the installation:

node --version
npm --version

Step 3: Install N8N

Install N8N globally using npm:

sudo npm install n8n -g

Step 4: Configure N8N

Create a directory for N8N configuration:

mkdir ~/.n8n
cd ~/.n8n

Create a basic configuration file:

nano config/index.js

Add the following configuration:

module.exports = {
  host: '0.0.0.0',
  port: 5678,
  protocol: 'http',
  database: {
    type: 'sqlite',
    database: 'database.sqlite'
  },
  credentials: {
    overwrite: {
      endpoint: 'webhooks'
    }
  }
};

Step 5: Set Up Environment Variables

Create an environment file:

nano ~/.bashrc

Add these environment variables at the end:

export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=your_username
export N8N_BASIC_AUTH_PASSWORD=your_secure_password
export N8N_HOST=0.0.0.0
export N8N_PORT=5678
export N8N_PROTOCOL=http

Reload the environment:

source ~/.bashrc

Step 6: Install and Configure Nginx (Reverse Proxy)

Install Nginx:

sudo apt install nginx -y

Create an Nginx configuration for N8N:

sudo nano /etc/nginx/sites-available/n8n

Add the following configuration:

server {
    listen 80;
    server_name your-domain.com;  # Replace with your domain

    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_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;
        proxy_cache_bypass $http_upgrade;
    }
}

Enable the site:

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 7: Set Up SSL with Let’s Encrypt (Optional but Recommended)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Obtain SSL certificate:

sudo certbot --nginx -d your-domain.com

Step 8: Create a Systemd Service

Create a systemd service file for N8N:

sudo nano /etc/systemd/system/n8n.service

Add the following content:

[Unit]
Description=n8n workflow automation
After=network.target

[Service]
Type=simple
User=n8n
ExecStart=/usr/bin/n8n start
Restart=on-failure
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=n8n
Environment=NODE_ENV=production
Environment=N8N_BASIC_AUTH_ACTIVE=true
Environment=N8N_BASIC_AUTH_USER=your_username
Environment=N8N_BASIC_AUTH_PASSWORD=your_secure_password
Environment=N8N_HOST=0.0.0.0
Environment=N8N_PORT=5678

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable n8n
sudo systemctl start n8n

Check the service status:

sudo systemctl status n8n

Step 9: Configure Firewall

Set up UFW firewall:

sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable

Step 10: Database Optimization (Optional)

For production use, consider switching from SQLite to PostgreSQL:

Install PostgreSQL:

sudo apt install postgresql postgresql-contrib -y

Create a database and user:

sudo -u postgres psql
CREATE DATABASE n8n;
CREATE USER n8nuser WITH PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE n8n TO n8nuser;
\q

Update your N8N environment variables:

export DB_TYPE=postgresdb
export DB_POSTGRESDB_HOST=localhost
export DB_POSTGRESDB_PORT=5432
export DB_POSTGRESDB_DATABASE=n8n
export DB_POSTGRESDB_USER=n8nuser
export DB_POSTGRESDB_PASSWORD=secure_password

Step 11: Performance Tuning

For better performance on your Ramnode VPS:

Increase Node.js memory limit:

export NODE_OPTIONS="--max-old-space-size=2048"

Configure N8N for production:

export N8N_LOG_LEVEL=warn
export N8N_METRICS=true
export EXECUTIONS_DATA_PRUNE=true
export EXECUTIONS_DATA_MAX_AGE=168  # Keep executions for 1 week

Step 12: Backup Strategy

Create a backup script:

nano ~/backup-n8n.sh
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/home/n8n/backups"
mkdir -p $BACKUP_DIR

# Backup N8N data
tar -czf $BACKUP_DIR/n8n_backup_$DATE.tar.gz ~/.n8n/

# Backup database (if using PostgreSQL)
pg_dump -h localhost -U n8nuser n8n > $BACKUP_DIR/n8n_db_$DATE.sql

# Keep only last 7 backups
find $BACKUP_DIR -name "n8n_backup_*.tar.gz" -mtime +7 -delete
find $BACKUP_DIR -name "n8n_db_*.sql" -mtime +7 -delete

echo "Backup completed: $DATE"

Make it executable and add to crontab:

chmod +x ~/backup-n8n.sh
crontab -e
# Add this line for daily backups at 2 AM
0 2 * * * /home/n8n/backup-n8n.sh

Step 13: Monitoring and Logs

Monitor N8N logs:

sudo journalctl -u n8n -f

Set up log rotation:

sudo nano /etc/logrotate.d/n8n
/var/log/n8n/*.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 644 n8n n8n
}

Security Best Practices

  1. Regular Updates: Keep N8N, Node.js, and system packages updated
  2. Strong Authentication: Use complex passwords and consider 2FA
  3. Firewall: Only open necessary ports
  4. SSL/TLS: Always use HTTPS in production
  5. Regular Backups: Implement automated backup strategy
  6. Monitoring: Set up monitoring and alerting

Accessing Your N8N Instance

Once everything is set up, you can access N8N through:

  • HTTP: http://your-domain.com or http://your-server-ip
  • HTTPS: https://your-domain.com (if SSL is configured)

Log in using the credentials you set in the environment variables.

Troubleshooting Common Issues

Service Won’t Start

sudo systemctl status n8n
sudo journalctl -u n8n --no-pager

Port Already in Use

sudo netstat -tulpn | grep :5678
sudo kill -9 <process-id>

Memory Issues

Consider upgrading your Ramnode VPS plan or optimizing workflows to use less memory.

Database Connection Issues

Verify database credentials and ensure the database service is running.

Conclusion

You now have a fully functional N8N installation running on your Ramnode VPS. This setup provides a solid foundation for workflow automation with proper security, monitoring, and backup procedures in place.

Remember to regularly update your installation and monitor resource usage to ensure optimal performance. With N8N running on Ramnode’s reliable infrastructure, you can now automate workflows, integrate various services, and streamline your business processes.

For advanced configurations and scaling, consider exploring N8N’s extensive documentation and community resources to unlock the full potential of your workflow automation platform.