Deploy NodeJS application and html website with PostgresSQL and Nginx as a server
- OS: Linux20.04 LTS
- Server: Nginx 1.20
- NodeJS: nvm 0.39
- Database: PostgreSQL 12.11
ssh-keygen -t rsaObtain public key:
cat ~/.ssh/id_rsa.pubP.S. This public key to be put in authorized_keys in our remote server
sudo apt update
sudo apt upgradeInstall postgresql & postgresql-contrib packages.
sudo apt install postgresql postgresql-contribStart postgres service
sudo systemctl start postgresql.serviceEdit the postgresql.conf
listen_addresses = '*'Edit the pg_hba.conf file and add the following entry at the very end of file:
host all all 0.0.0.0/0 md5
host all all ::/0 md5Download & run nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bashConfigure nvm bash path
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"Install node 16
nvm install 16- Install:
sudo apt install nginx-full- Domain Configuration:
cd /etc/nginx/sites-available
nano example.comInside that file we will insert the following:
server {
server_name domain.com www.domain.com;
root /var/www/website;
index index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
Add inbound rules: Ports: 22, 22/tcp, 2222, 2222/tcp, Nginx Full, 5432, OpenSSH
sudo ufw allow [port/app]
sudo ufw enable
sudo ufw reload