nginx ubuntu deploying a static react application

November 29, 2018 1.7k views
DigitalOcean Deployment Development Node.js Nginx Applications 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: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04. 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 mydomain.com/projectName 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.

Be the first one to answer this question.