1. First setup Nginx on Ubuntu
2. Install Node in Server
- First install Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
- Check Node Version Manager version
nvm --version
- Install Node ( This will install latest version of node & npm )
nvm install node
- Check Node & npm version
node -v
npm -v
- If you want specific version of Node then only run this command
nvm install 17.9.1
node -v
v17.9.1
npm -v
8.11.0
3. Setup NestJS
- Install package nestjs/cli in global
npm i -g @nestjs/cli
- Create NestJS app
cd /var/
sudo mkdir nest-project
sudo chmod -R 777 nest-project
cd nest-project
nest new .
4. Configure NGINX Reverse Proxy
- Default NestJS app is running on 3000 port so we have to setup reverse proxy that port to 80 port
sudo nano /etc/nginx/sites-enabled/default
- Update default file of nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
#Reverse proxy for accessing Nest app
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
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;
}
}
- Restart nginx for reflecting changes
sudo systemctl restart nginx
4. Configure PM2
- Build the NestJS app
cd /var/nest-project
npm run build
- Install pm2 in global
npm install pm2 -g
- Start PM2 app
pm2 start npm --name "app" -- start
Top comments (0)