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.

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.

×
1 answer

Hello,

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:

https://www.digitalocean.com/community/questions/how-to-troubleshoot-common-nginx-issues-on-linux-server

Regards,
Bobby

Submit an Answer