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

WBOY
Release: 2023-05-16 13:01:18
forward
1119 people have browsed it

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!