问题

nginx部署前端项目,
访问网站首页没问题,即网站根目录。xxxxxx.com
直接访问其他目录时,报404。xxxxxx.com/home

解决方法

更改nginx配置文件。

location / {
		root   html;
        index  index.html index.htm;
}

替换为:

location / {
		root   html;
        index  index.html index.htm;
         
        try_files $uri $uri/ /index.html;
}

再次访问。问题解决。

注意

如果你的网址是https格式的,
那么需要加到监听443端口的location /里。
如果不是,加到80端口。

更多推荐