If you would like to add a new domain or subdomain later on here are the required steps
sudo mkdir -p /var/www/subdomain.example.com/html
sudo chown -R $USER:$USER /var/www/subdomain.example.com/html
sudo chmod -R 755 /var/www/subdomain.example.com
sudo nano /etc/nginx/sites-available/subdomain.example.com
This is the nginx config file for the subdomain
server {
listen 80;
server_name subdomain.example.com www.subdomain.example.com;
location / {
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_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3001;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
sudo ln -s /etc/nginx/sites-available/subdomain.example.com /etc/nginx/sites-enabled/
sudo systemctl restart nginx
sudo ufw allow 3001
//link
127.0.0.1:3001
//ssl
sudo certbot --nginx -d subdomain.example.com -d www.subdomain.example.com
myemail@email.com
sudo certbot renew --dry-run
If you have installed PM2 then you can start the server and name it "subdomain" or how you wish
//PM 2 start with name
pm2 start npm --name "subdomain" -- start