How do I configure my Nginx server to work with a React app in a subfolder?
10,023
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.
Author by
shane
Updated on June 19, 2022Comments
-
shane about 2 years
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?