Nginx config file to deploy a React app to your server

back
Deploy React app to a ubuntu server in your VPS with Nginx.
Chen, 2020-02-06

I suppose you are already familiar with Nginx. The Nginx config file for a react-app (or any other static websites):

To do this we simply add a config file in the /etc/nginx/sites-available:

sudo nano /etc/nginx/sites-available/webclient
server {
    server_name www.example.com; # your domain

    location / {
            root /var/www/webclient; # your build files directory
            try_files $uri /index.html;
            index index.html;
    }
    }

And then enable the file by creating a link from it to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/webclient /etc/nginx/sites-enabled/

Test for syntax errors:

sudo nginx -t

Restart Nginx to enable your changes:

sudo systemctl restart nginx