sudo apt-get install nginx
sudo nano /etc/nginx/sites-enabled/default
Here is the content
server {
listen 80 default_server;
listen [::]:80 default_server;
client_max_body_size 1000M;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name YOUR_DOMAIN_GOES_HERE;
location / {
proxy_pass http://localhost:7001; #whatever port your app runs on
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 systemctl restart nginx
sudo ufw status
Output:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
If not active, activate it by running
sudo ufw enable
To additionally let in HTTPS traffic, we can allow the Nginx Full profile and then delete the redundant Nginx HTTP profile allowance:
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
sudo ufw status
Output:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python3-certbot-nginx
sudo certbot --nginx -d YOUR_DOMAIN_WITHOUT_SUBDOMAIN_PART -d YOUR_DOMAIN_WITH_SUBDOMAIN_PART
For example: sudo certbot — nginx -d myawesomewebsite.com -d service.myawesomewebsite.com
Note: The YOUR_DOMAIN_WITH_SUBDOMAIN_PART is optional
First backup the previous config file
cd /etc/nginx/conf.d
sudo cp default.conf default.conf.bak
Now update the config file
sudo nano default.conf
curl -fsSL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install npm
sudo npm install pm2 -g
Now choose the project's root directory and start the initiator script with pm2
pm2 start index.js
pm2 monit