sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw status
systemctl status nginx
curl -4 icanhazip.com
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Optional:
sudo vi /etc/nginx/sites-available/example.com
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
sudo systemctl status certbot.timer
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
node -v
sudo apt install build-essential
const http = require('http');
const hostname = 'example.com';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
curl http://example.com:3000
sudo npm install pm2@latest -g
pm2 start hello.js
pm2 startup systemd
4b. The last line of the resulting output will include a command to run with superuser privileges in order to set PM2 to start on boot:
[PM2] Init System found: systemd
sammy
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy
pm2 save
4e. You have now created a systemd unit that runs pm2 for your user on boot. This pm2 instance, in turn, runs hello.js.
sudo systemctl start pm2-sammy
systemctl status pm2-sammy
pm2 stop app_name_or_id
pm2 restart app_name_or_id
pm2 list
pm2 info app_name
pm2 monit
sudo nano /etc/nginx/sites-available/example.com
server {
...
location / {
proxy_pass http://localhost:3000;
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;
}
...
}
server {
...
location /app2 {
proxy_pass http://localhost:3001;
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;
}
...
}
sudo nginx -t
sudo systemctl restart nginx