Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure my Nginx server to work with a React app in a subfolder?

I am trying to deploy a React application in a subfolder on my Nginx server.

The location of this React app is structured like: www.example.com/reactApp.

I tried to set up my current nginx.conf like so:

server {
    ..other configs..

    location /reactApp {
        root /var/www;
        index reactApp/index.html;
        try_files $uri $uri/ /index.html;
    }  

    ..other configs..
}

This has not worked. What do I need to change to fix my subfolder routing?

like image 707
shane Avatar asked Oct 19 '17 18:10

shane


1 Answers

The last component of the try_files statement should be a URI. Assuming that your index.html file is located under the /var/www/reactApp subfolder, you should use:

location /reactApp {
    root /var/www;
    index  index.html;
    try_files $uri $uri/ /reactApp/index.html;
}

See this document for more.

like image 77
Richard Smith Avatar answered Oct 23 '22 04:10

Richard Smith