Nginx configuration of React project Url after direct input routing path times 404 problem resolution
- 2020-05-13 04:38:35
- OfStack
preface
Nowadays, react is widely used. Recently, I encountered a problem in the configuration of react project, and finally found a solution by searching relevant materials. Therefore, I want to summarize 1 and share it with friends in need.
Found the problem
As you know, when we're done writing the project and deploying it, my configuration is simple
location /demo {
root E:/;
index index.html index.htm;
}
There is a problem with this configuration, which can only be accessed by http://localhost/demo/.
If you want to access the inside of the other interfaces, such as http: / / localhost demo page1, so can't find the page 404.
But when I was developing it, I really had no problem. I could access it. I just thought, "do I have to use node for the project?" No, maybe I can't configure it myself.
The solution
Finally, a solution was found, and an extra line was found in someone else's nginx.config.
location /demo {
root E:/;
# And then you add this to it, and you get this url Add the routing configuration directly afterwards path .
try_files $uri /demo/index.html;
index index.html index.htm;
}
Why? It's not clear, but it works.
Under this marker 1, for later use.
conclusion