QUAPE Website

How to Deploy n8n on Ubuntu 24.04

How to Deploy n8n on Ubuntu 24.04

Looking for a guide on how to deploy n8n on Ubuntu 24.04? n8n is a powerful open-source automation tool that connects your applications and services seamlessly. This comprehensive tutorial will show you exactly how to deploy n8n on Ubuntu 24.04 with PostgreSQL database, Nginx reverse proxy, and SSL security.

By following this step-by-step guide, you’ll have a production-ready n8n instance running on your Ubuntu 24.04 server. Let’s begin the installation process.

Prerequisites

Before you deploy n8n ubuntu server, make sure you have:

  • Ubuntu 24.04 VPS or dedicated server
  • Root or sudo access
  • Domain name configured (e.g., n8n.example.com)
  • Minimum 4GB RAM
  • 50GB disk space

#1 Create Dedicated n8n User

Create a dedicated user account for better security when you deploy n8n ubuntu:

adduser n8n

Add sudo privileges:

usermod -aG sudo n8n

Switch to n8n user:

su - n8n

#2  Install Node.js with NVM

To successfully deploy n8n ubuntu, you need Node.js. Install NVM (Node Version Manager) first:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Load NVM configuration:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Reload bash configuration:

source ~/.bashrc

Install the latest Node.js version:

nvm install node

#3 Install n8n

Now install n8n globally using npm:

sudo npm install -g n8n

This installs n8n system-wide, allowing you to run it as a service when you deploy n8n ubuntu production environment.

#4 Configure n8n Environment

Create n8n configuration directory and environment file:

nano ~/.n8n/.env

Add these basic configuration lines:

WEBHOOK_URL=https://n8n.example.com
WEBHOOK_TUNNEL_URL=https://n8n.example.com
N8N_HOST=0.0.0.0
N8N_PORT=5678

Replace n8n.example.com with your actual domain name.

#5 Install and Configure PostgreSQL

For production deployment, PostgreSQL is recommended. Install PostgreSQL:

sudo apt install postgresql postgresql-contrib

Switch to postgres user:

sudo su postgres

Access PostgreSQL shell:

psql

Create database and user for n8n:

CREATE DATABASE n8db;
CREATE USER usern8 WITH SUPERUSER PASSWORD 'SecurePassword';
GRANT ALL PRIVILEGES ON DATABASE n8db TO usern8;
\q

Exit postgres user:

exit

#6 Configure Database Connection

Update n8n environment file with database settings:

nano ~/.n8n/.env

Add PostgreSQL configuration:

DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=localhost
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8db
DB_POSTGRESDB_USER=usern8
DB_POSTGRESDB_PASSWORD=SecurePassword
DB_POSTGRESDB_SCHEMA=n8db

Remember to use a strong password for production environments.

#7 Create Systemd Service

To deploy n8n ubuntu as a background service, create a systemd service file:

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

Paste the following configuration:

[Unit]
Description=n8n
After=network.target

[Service]
User=n8n
WorkingDirectory=/home/n8n/.n8n
EnvironmentFile=/home/n8n/.n8n/.env
ExecStart=/usr/bin/n8n
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Reload systemd and enable n8n service:

sudo systemctl daemon-reload
sudo systemctl enable --now n8n

Check service status:

sudo systemctl status n8n

#8 Install and Configure Nginx

Install Nginx as reverse proxy:

sudo apt install nginx

Create Nginx configuration for n8n:

sudo nano /etc/nginx/conf.d/n8n.conf

Add this configuration:

upstream n8n {
    server 127.0.0.1:5678;
}

server {
    listen 80;
    server_name n8n.example.com;
    access_log /var/log/nginx/n8n.access.log;
    error_log /var/log/nginx/n8n.error.log;
    
    location / {
        proxy_pass http://n8n;
        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_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Restart Nginx:

sudo systemctl restart nginx

#9 Enable SSL Certificate

Secure your n8n installation with free SSL certificate from Let’s Encrypt:

sudo apt install python3-certbot-nginx

Obtain and install SSL certificate:

sudo certbot --nginx -d n8n.example.com

Follow the prompts to complete SSL setup. Certbot automatically configures Nginx for HTTPS.

#10 Access Your n8n Instance

Open your browser and navigate to:

https://n8n.example.com

You’ll see the n8n setup page. Create your admin account and start building workflows!

Best Practices for Production

When you deploy n8n ubuntu production server, consider these recommendations:

Security Measures:

  1. Use strong passwords for database and n8n accounts
  2. Enable firewall (UFW) and allow only necessary ports
  3. Keep Ubuntu and n8n updated regularly
  4. Implement fail2ban for brute force protection

Performance Optimization:

  1. Monitor resource usage with htop or similar tools
  2. Set up database backups with pg_dump
  3. Configure log rotation to prevent disk space issues
  4. Use connection pooling for database efficiency

Monitoring and Maintenance:

  1. Set up monitoring tools like Prometheus or Netdata
  2. Configure automated backups for n8n workflows
  3. Monitor SSL certificate expiration
  4. Review logs regularly for errors

For detailed configuration options, visit the official n8n documentation.

Recommended VPS Hosting

Looking for reliable hosting to deploy n8n ubuntu server? QUAPE VPS offers powerful infrastructure built on AMD EPYC processors and ultra-fast NVMe SSD storage. With 99.9% uptime guarantee, full root access, and 24/7 expert support, QUAPE provides the performance your automation workflows need at competitive pricing.

Get started with QUAPE VPS Hosting and experience the difference of enterprise-grade hardware for your self-hosted applications.

Final Thoughts

You’ve successfully learned how to deploy n8n ubuntu 24.04 with PostgreSQL, Nginx, and SSL encryption. This setup provides a secure, production-ready environment for your workflow automation needs.

n8n’s flexibility allows you to connect hundreds of applications without writing code. From simple data transfers to complex multi-step workflows, your n8n instance is now ready to handle any automation task.

Athif Quape
Athif Quape

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's Get in Touch!

Dream big and start your journey with us. We’re all about innovation and making things happen.