Home  >  Article  >  Operation and Maintenance  >  How to solve the problem of 404 when configuring Nginx React project

How to solve the problem of 404 when configuring Nginx React project

WBOY
WBOYforward
2023-05-16 13:01:181136browse

As we all know, after writing the project, we need to deploy the project. The configuration is very simple

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:/;

#After adding this, 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 configuring Nginx React project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete