Server - Contents

Express - Deployment

revised: 22-Dec-2021

Premises:
- That a Node.js-enable environment on the PC with a 'stack' folder - which, via an FTP client (eg.FileZilla), is synchronized with the 'stack'' folder on the server.
- Both PC and Server have tested, via http on port:5000 by running the command [npm run dev] within its main directory (stack/) then visit localhost:5000 or http://[MySeverIP]:5000
- That the config.env has an entry: PORT=8080 (no quotes necessary)
- That the service; Either by PM2 or by stack.service is actively serving port:8080 Check the output with this bash command: curl http://localhost:8080/
- [Optional]Nginx Webserver is serving the iRedmail app, http://[MySeverIP]/mail

Recommended Strategy

Step1: Create a website SSL certificate via Let'sEncrypt

Following the instructions from Let'sEncrypt - see SSL Certificate for Websites The ExpressJS project 'stack'' will then be service by Nginx, ultimately on port 443 with a LetsEncrypt certificate.

Step2: Set Nginx to serve the Express-Stack site

Assumption: Nginx installed and active such it shows its default page at http://[MySeverIP]

a. Obtain a SSL Certificate using Cerbot
1. Via PuTTy on the remote server, do these commands

sammy@imega: sudo cp /var/www/html/index.html /var/www/html/xxindex.html
sammy@imega: sudo nano /var/www/html/index.html and place between html tags 'It works'

Restarting Nginx, and visiting the link to your domain, the page should read simply: 'It works'.

Install cerbot (see this page: Certbot-SSL) and create the certificate and, if iRedmail is installed, do the soft links to those certificate parameters of iRedmail as described therein.

b. Configure Nginx to Proxy from the stack.service
2. Create a new virtual host by opening Webmin→ Servers→ Nginx Webserver and do the following:
Via 'Create Virtual Host' and in 'Server Name', put 'myexample.com.conf' (replace with your domain name) and in 'config, place the script below similar to this but with your domain name:

nginx-login2.txt

sammy@imega:sudo systemctl restart nginx

Thereafter open the browser with https://myexample.com. Your Express website should appear.

Express2 Express-PartB
Express-Deploy Express-Extras