nginx ubuntu deploying a static react application

November 29, 2018 3.4k views
Nginx Node.js DigitalOcean Applications Deployment Development JavaScript Ubuntu 18.04

I have a droplet running nginx on ubuntu 18.04 and have followed this tutorial for setting up a server block: So now I have mydomain set up in /var/www/mydomain/ with an html folder and index.html file that works perfectly fine. But now I want to be able to deploy static pages built from react. So I created a folder called /projects/ in /var/www/mydomain/ and then placed the production build within. Now I go into the /etc/nginx/sites-available/mydomain and add location /projectName { root /var/www/mydomain/projects/projects/build; try_files $uri /index.html; } but this never seems to work. When I navigate to I’m always either taken to the home page, given a 403 or 404 error, or sometimes it does successfully serve me the proper project index.html but the page does not render as if the javascript is not compiling properly. The build is just a static page with its own resources so I know I don’t need to start a pm2 process, its just a matter of having nginx route the location to the build folder properly, but I can’t get it to work. Thank you the help.

1 Answer


I think that this might be a problem with your file permissions, what I could suggest is following the steps here on how to troubleshoot common Nginx problems:


Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!