Cryptex Technologies
Cryptex Technologies

Reputation: 1163

How to Start react application in production mode or in nginx server

I have created the production build using

npm run build

After creating of successful build I have run the command

serve -s build

how can i start my application on production server in detach mode or in background mode. It is working in my local fine.

Upvotes: 0

Views: 5371

Answers (1)

Cryptex Technologies
Cryptex Technologies

Reputation: 1163

Finally I got the solution to start the react application or build of application on nginx server We’ll need to install node to get working with our React app. The following will do the job to get the latest version of Node at the time of running.

sudo apt-get update
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential

This installs Node, npm, and the build tools that come in handy for npm.

Once Node & npm are installed, we’re going to need to install two tools:

Clone your repository on your machine

sudo mkdir /var/www
cd /var/www/

Take the clone or paste the code in the current directory, then change the directory.

cd sample-app

Install the project on the system.

sudo npm install

The You need to create the optimized production build of the project

sudo npm run build

Install and Configure Nginx to serve your application

sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/default 

and paste the below code

server {
  listen 80 default_server;
  root /var/www/sample-app/build;
  server_name localhost;
  index index.html index.htm;
  error_page 404 /;
  location / {
  }
}

Now you need to start your server

sudo service nginx start

Upvotes: 2

Related Questions