Deploy React App With Nginx

Tram Ho

In this article, I would like to share the method to deploy Reactjs project on Ubuntu server

Ubuntu Server

First, of course, we need a Linux server , we will use the popular OS Ubuntu 18.04 , the requirements for configuration are as follows:

  • 25GB memory or more
  • Ram 2GB or more
  • CPU: 1core or more 😄

Login to the server

Next, we will install the tools needed to run applications and npm nodejs reactjs is (if you have developed web applications with React, you definitely know what they are already).
Install Node and npm on Ubuntu server with curl with the following commands: Install curl

Install node and npm

Check the result

Install nginx

The webserver I will use is nginx , install nginx on Ubuntu server as follows:

Proceed to deploy

OK, installing the environment is enough. Next, we will deploy the deployment .
First we clone the project

Install the necessary packages for the project

Note that if your project uses a different tool to manage package like yarn , you need to install it first.
After installing the packages , try to start the application to test in the dev environment:

Open a browser and check the link http: // SERVER_IP: PORT .
If everything looks good, stop the terminal with ctrl + c and go to the next step.

Set up nginx

Create a config file for your application

Then add the following setup code to the newly created file and save it. (In this step assume you have run the application build command at the build directory in the project directory).

Next, you need to enable the config file you just created:

Restart nginx :

OK done, if everything goes smoothly then your application is ready, check the link: http: // your_ip_address

Share the news now

Source : Viblo