nginx ubuntu deploying a static react application

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


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:

Regards, Bobby