I’m working on a multi-tenant application in React and some clients want to upload .html files to the root of the project to use google console and things like that. I would not like all those files to be mixed with the application code so apart from the following code:
location / {
try_files $ uri /index.html = 404;
}
I would like to add in NGINX a location block that allows me to divert to another folder any other .html file that starts in /, excluding cases like /static/example.html.
Example:
/ -> React default
/static/*.html -> React default
/*.html -> Derive to new folder
I would appreciate any help in this regard.
I tried something like this…
location /*.html {
root /extras_folder;
}
location / {
root /project_folder;
try_files $uri /index.html =404;
}
But does not work
2
Answers
What about this?
This looks in
/project_folder
first, in/extras_folder
second and, if still no file is found finally serves/project_folder/index.html
(or 404 if that file doesn’t exist).You’d put uploaded files into
/extras_folder
in this case.This adheres to the rules you described: