news
Serverspace Technologies in the UAE: Launch of Falconcloud
VB
August 8, 2022
Updated June 7, 2023

Nginx plus React app on Ubuntu 20.04

Linux NGINX Ubuntu

Intro

This article will describe you how to prepare the server, install and depoy ReactOS application onto Nginx web-server.

In the Serverspace you can create a server with already installed app "Nginx".

Server preparing

To install React app on your own server you should have:

  • Server under Ubuntu operation system with root access or sudo membership
  • Domain name with correct DNS-settings. A-records should be "pointed" to your server's public IP

Installation process

  • Firstly, you need to increase your privileges, then install NodeJS
sudo -s
apt install nodejs npm -y
  • Next step is npx package installation. Just run:
npm i -g npx -y
  • To check is everything installed OK please run:
node -v
npm -v
npx -v

You should see something like that:

pic.1

  • To create your app you should use this command:
npx create-react-app <YOUR_APP_NAME>

Compilation takes much time, so be patient. When the process finished, you will see this:

pic.2

Web-server install

To work with your app you need any webserver, e.g. Nginx. To install it run:

  • apt install -y nginx

Then create basic config-file:

cat <<EOF > /etc/nginx/sites-enabled/<DOMAIN_NAME>
server {
listen 80;
root /var/www/<DOMAIN_NAME>;
index index.php index.html;
server_name <DOMAIN_NAME> www.<DOMAIN_NAME>;
location / {
}
}
EOF

pic.3

Application launch

  • Next stage is app launch:
cd /home/<USERNAME>/<APPNAME>
npm start

You should see something similar to picture below:

pic.4

Open the URL http://<YOUR_SERVER_IP>:3000 in the browser. In case you see an answer like below - terminate the app via CTRL+C and go to the next step:

pic.5

  • Go to your app's directory and compile it:
cd /home/<USERNAME>/<MYAPP>
npm run build

Wait a little. Expected result looks like:

pic.6

  • Finally, just copy compiled app files to the website directory, enable and restart Nginx:
mkdir /var/www/<DOMAIN_NAME> && cp /home/<USERNAME>/<MYAPP>/build/* /var/www/<DOMAIN_NAME>/
systemctl enable nginx && service nginx restart

pic.7

Final check

To check the result just open your website in browser:

pic.8

Conclusion

In this article we discribed how to install NodeJS, create your first app and deploy it into your website with Nginx webserver.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.