n8n is a versatile workflow automation tool that enables you to automate tasks across different services. In this guide, we’ll walk you through the process of setting up n8n on an Ubuntu server with HTTPS enabled.

Prerequisites

Before you start, make sure you have:

  • A Ubuntu server with root or sudo access.
  • A domain pointing to your server’s IP address (e.g., n8n.domain.xyz).
  • SSL certificate and private key files for your domain.

Process

Step 1: Update System Packages
Begin by updating your system packages to the latest version:


sudo apt update

sudo apt upgrade -y

Step 2: Install Node.js and npm
n8n requires Node.js and npm. Install them using the following commands:


sudo apt install nodejs -y

sudo apt install npm -y

Step 3: Install n8n
With npm installed, you can now install n8n globally:


npm install n8n -g

Step 4: Install and Configure Nginx
Nginx will serve as the reverse proxy server for n8n to handle HTTPS connections.

Install Nginx:


sudo apt install nginx -y

Verify that Nginx is running:


sudo systemctl status nginx

Create a new Nginx configuration file for n8n:


sudo vim /etc/nginx/sites-available/n8n.conf

Insert the following configuration into the file, customizing the server name and paths to SSL certificates as needed:


server {

listen 80;

server_name n8n.domain.xyz;

return 301 https://$host$request_uri;

}

server {

listen 443 ssl;

server_name n8n.domain.xyz;

ssl_certificate /home/n8nuser/certs/cert.pem;

ssl_certificate_key /home/n8nuser/certs/key.pem;

ssl_protocols TLSv1.2 TLSv1.3;

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

location / {

proxy_pass http://localhost:5678;

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_connect_timeout 60s;

proxy_send_timeout 60s;

proxy_read_timeout 60s;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection “upgrade”;

}

}

Enable the configuration by linking it to the sites-enabled directory:


sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/

Test the Nginx configuration for syntax errors:


sudo nginx -t

Restart Nginx to apply the changes:


sudo systemctl restart nginx

Step 5: Configure n8n Environment Variables
Set the environment variables needed for n8n:


export N8N_SECURE_COOKIE=false

export WEBHOOK_URL=https://n8n.domain.xyz

Step 6: Install and Configure PM2
PM2 is a process manager for Node.js applications that will help keep n8n running in the background.

Install PM2 globally:


npm install pm2 -g

Start n8n using PM2:


pm2 start n8n

Ensure PM2 starts automatically on system boot:


pm2 startup

You will see a command output from PM2. Execute the command to enable PM2 at startup. For example:


sudo env PATH=$PATH:/home/n8nuser/.nvm/versions/node/v18.20.5/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u n8nuser — hp /home/n8nuser

Conclusion

You’ve successfully installed n8n on your Ubuntu server with HTTPS. You can now access your n8n instance securely via your domain. Enjoy automating your workflows with n8n! For further customization and integration ideas, refer to the official n8n /.

Author Of article : Sebastian Torralba Read full article