Giter VIP home page Giter VIP logo

install-n8n-with-pm2's Introduction

Install-n8n-with-pm2

Make sure you have sudo privilege

sudo -s

OS Updates

Before doing anything else, update your operating system by running these two commands:

apt update && sudo apt upgrade -y

Prerequisites

Add the NodeSource APT repository for Node 20

sudo curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash &&
apt-get install nodejs -y

Install NGINX

NGINX server and the SSL configuration requires

apt install nginx -y

Check Status of NGINX (optional)

systemctl status nginx

Configure NGINX

cd /etc/nginx/sites-available/ &&
nano n8n.conf

Now insert a copy of the below example configuration and replace

server {
    server_name n8n.domain.tld;
    listen 80;

    location / {
        proxy_pass http://localhost:5678;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
    }
}

Now linking the file we have just created

ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/ &&
nginx -t &&
systemctl reload nginx

Install PM2

npm install pm2 -g

Install n8n

npm install n8n -g

Start n8n with pm2

pm2 start n8n

Setup auto-start n8n on machine restart

pm2 startup && pm2 save

Restart the n8n service

pm2 restart n8n

pm2 config

create pm2 config with pm2 init simple replce with below code

module.exports = {
    apps : [{
        name   : "n8n",
        env: {
            // N8N_EMAIL_MODE: "smtp",
            // N8N_SMTP_HOST: "smtp.gmail.com",
            // N8N_SMTP_PORT: "465",
            // N8N_SMTP_USER: "[email protected]",
            // N8N_SMTP_PASS: "password",
            // N8N_SMTP_SSL: "true",
            N8N_PROTOCOL: "https",
            GENERIC_TIMEZONE: "Asia/Kolkata",
            TZ: "Asia/Kolkata",
            N8N_HOST: "n8n.domain.tld",
            WEBHOOK_URL: "https://n8n.domain.tld/",
            N8N_EDITOR_BASE_URL: "https://n8n.domain.tld/",
            N8N_ENDPOINT_WEBHOOK: "prod/v1",
            N8N_ENDPOINT_WEBHOOK_TEST: "test/v1",
            N8N_METRICS: true,
        }
    }]
}

### if you do not have domain then use below config

module.exports = {
    apps : [{
        name   : "n8n",
        env: {
            GENERIC_TIMEZONE: "Asia/Kolkata",
            TZ: "Asia/Kolkata",
            N8N_HOST: "your_server_ip_here",
            WEBHOOK_URL: "your_server_ip_here:5678",
            N8N_EDITOR_BASE_URL: "your_server_ip_here:5678",
            N8N_ENDPOINT_WEBHOOK: "prod/v1",
            N8N_ENDPOINT_WEBHOOK_TEST: "test/v1",
            N8N_SECURE_COOKIE: false,
        }
    }]
}

If you have a Custom domain then change the below config as well. If not then you can go to http://SERVER-IP:5678

N8N_HOST: "n8n.domain.tld",
WEBHOOK_URL: "n8n.domain.tld",
N8N_EDITOR_BASE_URL: "n8n.domain.tld",

Start with pm2 config

pm2 start ecosystem.config.js

Start with pm2 with update config

pm2 restart ecosystem.config.js --update-env

We are now ready to configure UFW.

ufw app list

Now allow bothudp and tcp for Nginx Full, OpenSSH & 5678,443,80 to be accessed from the internet:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw allow 5678/tcp
sudo ufw allow 443/tcp
sudo ufw allow 80/tcp

Enable firewall

ufw enable

update (optional)

npm update -g  n8n

Please refer official docs to import or export workflows and credentials.

install-n8n-with-pm2's People

Contributors

ddm21 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.