This setup applies to any NodeJS app that needs NGinX reverse proxy and SSL configuration.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm install node
sudo git clone <repo address>
cd <project folder>
npm i
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
sudo ufw allow 80
sudo ufw allow 443
It is being done for wildcard config and for no subdomain.
You will need to have access to your DNS register in order to complete this part.
sudo certbot certonly --manual --preferred-challenges dns -d *.<domain> -d <domain>
sudo cp /etc/letsencrypt/live/<domain>/fullchain.pem <path you want>
sudo cp /etc/letsencrypt/live/<domain>/privkey.pem <path you want>
As we are doing it using manual mode, because it was not possible in another way. This should be disabled.
sudo systemctl disable certbot.timer
sudo touch /etc/profile.d/<project name>-vars.sh
export APPPORT=<port to backend app>
export ADDRESSDB=<address of prod database>
export USERDB=<user to access prod database>
export PASSDB=<password to access prod database>
export NAMEDB=<name of prod database>
export PARAMSDB=<extra params for DB connection string>
export FRONTENDADDRESS=<frontend address>
export HTTPSKEYFILE=<location of SSL/TLS key>
export HTTPSCERTFILE=<location of SSL/TLS certificate>
export SALTROUNDS=<salt rounds for encripting>
export SECRETKEYHMAC=<secret for HMAC encryption>
export VIMEO_CLIENTID=<Vimeo clientid>
export VIMEO_CLIENTSECRET=<Vimeo client secret>
export VIMEO_ACCESSTOKEN=<Vimeo access token>
PS.: In DEV env there is an env variables named JWTDEVTOKEN
. It MUST NOT be set here, in PRODUCTION.
sudo ./nginx_install.sh
npm install pm2 -g
Install log rotate
pm2 install pm2-logrotate
Config it
pm2 set pm2-logrotate:compress true
pm2 start --name <app name> --log <path to combined log> --time <path to index.js>
pm2 startup
pm2 save
pm2 restart <app name>
sudo service nginx restart
Copy the script deploy.sh
to home directory and change paths, URL and app name within.