Skip to content

How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure

Netcloud24
Cloud Infrastructure Expert
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

 

Introduction

NestJS is a framework for building efficient, reliable, and scalable server-side applications with Node.js. In this guide, we’ll walk through the steps to deploy a NestJS application with Nginx on Ubuntu Linux and configure it for production use.

Prerequisites

Before proceeding, ensure you have:

  1. An Ubuntu Linux server
  2. A NestJS application ready for deployment
  3. Basic knowledge of Nginx and Ubuntu server administration

Steps to Deploy a NestJS Application with Nginx

    1. Install Node.js and npm: If Node.js and npm are not already installed on your Ubuntu server, install them using the following commands:
sudo apt update
sudo apt install nodejs npm
    1. Clone your NestJS application: Clone your NestJS application repository to your Ubuntu server.
    2. Install dependencies and build: Navigate to your NestJS application directory and install dependencies using npm:
cd /path/to/nestjs-app
npm install
npm run build
    1. Configure Nginx: Create a new server block configuration file for your NestJS application in Nginx:
sudo nano /etc/nginx/sites-available/nestjs-app

Inside the file, configure Nginx to proxy requests to your NestJS application:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
    1. Enable the server block: Create a symbolic link to enable the server block configuration:
sudo ln -s /etc/nginx/sites-available/nestjs-app /etc/nginx/sites-enabled/
    1. Test Nginx configuration: Test the Nginx configuration for syntax errors:
sudo nginx -t
    1. Reload Nginx: Reload Nginx to apply the changes:
sudo systemctl reload nginx
    1. Start your NestJS application: Start your NestJS application in production mode:
npm run start:prod

Conclusion

Congratulations! You have successfully deployed your NestJS application with Nginx on Ubuntu Linux and configured it for production use. Your application should now be accessible through the Nginx reverse proxy, providing improved performance and security.

Windows VPS Deutschland

Visual overview of How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure
Visual overview: How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure

Windows VPS España

Windows VPS Nederland

Windows VPS Italia

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Key topics covered in How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure
Key topics covered in this NetCloud24 guide.

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Windows RDS (Remote Desktop Services)

Windows VPS

Practical checklist for How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure
Practical checklist for applying the guidance in this article.
How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure
How to Deploy a NestJS Application with Nginx on Ubuntu Linux and Configure
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.