首页 > 文章列表 > Nginx配置React项目报404怎么解决

Nginx配置React项目报404怎么解决

nginx React
157 2023-05-11

代码:

location /demo {

 root E:/;

 index index.html index.htm;

}

这样配置的有一个问题,只能 http://localhost/demo/来访问。 

如果想访问里面的其它界面如 http://localhost/demo/page1的话,就报404找不到页面。 

可是开发的时候,确实没有问题,可以进行访问的,于就想难道必须得用node来项目吗?不会吧,也许是自己不会配置所致。 

解决方法

终于找到办法了,在其它人的nginx.config里发现多加了一行东西。

location /demo {

 root E:/;

 #加上了这个,就可以在url后面直接加路由上配置path了。

 try_files $uri /demo/index.html;

 index index.html index.htm;

}