Skip to content

Instantly share code, notes, and snippets.

@salman0ansari
Forked from bradtraversy/node_nginx_ssl.md
Last active March 19, 2024 09:48
Show Gist options
  • Save salman0ansari/e6b72ccd0e6256130e4700ba035040d0 to your computer and use it in GitHub Desktop.
Save salman0ansari/e6b72ccd0e6256130e4700ba035040d0 to your computer and use it in GitHub Desktop.
open port

1. Install Node/NPM

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

sudo apt install nodejs

sudo apt install npm

2. Setup PM2 process manager to keep your app running

Note

Make sure to change newtoken to something else

sudo npm i pm2 -g

pm2 start "./wago -admintoken newtoken"

You should now be able to access your app using your IP and port.

3. Setup ufw firewall

sudo ufw enable
sudo ufw status
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

4. Install NGINX and configure

sudo apt install nginx

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

Add the following to the location part of the server block

Note

Make sure to change ENTER_YOUR_IP_OR_DOMAIN_HERE to your IP or Domain

    server_name ENTER_YOUR_IP_OR_DOMAIN_HERE;

    location / {
        proxy_pass http://localhost:1337; 
        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;
    }
# Check NGINX config
sudo nginx -t

# Restart NGINX
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment