Home > Article > Operation and Maintenance > How to solve the problem of 404 when Nginx configures React project
Code:
location /demo {
root E:/;
index index.html index.htm;
}
There is a problem with this configuration, it can only be accessed via http://localhost/demo/.
If you want to access other interfaces inside such as http://localhost/demo/page1, you will get a 404 page not found.
But during development, there was indeed no problem and it could be accessed, so I thought, do I have to use node for the project? No, maybe it’s because I don’t know how to configure it.
Solution
Finally found a solution. I found an extra line added in other people's nginx.config.
location /demo {
root E:/;
#With this added, you can add the route directly after the url to configure the path.
try_files $uri /demo/index.html;
index index.html index.htm;
}
The above is the detailed content of How to solve the problem of 404 when Nginx configures React project. For more information, please follow other related articles on the PHP Chinese website!