nuxt项目部署到nginx,已在nginx配置 location / { try_files $uri $uri/ /; root html; index index.html index.htm;
}解决了因路由问题引起的404问题,但是只跳转到首页,并未根据路由的不同显示其他内容。也就是说无论http://domain/xxx/5af还是http://domain/xxx/6bf都是显示的首页内容。后面尝试过其他nginx配置# one
location / { try_files $uri $uri/ /index.html last; root html; index index.html index.htm;
} # two
location / { try_files $uri $uri/ @router; index index.html;
} location @router { rewrite ^.*$ / last;
}均以失败告终。在locahost环境下,一切正常。所以不知道nginx配置哪里有问题,请大家指教。作为刚入IT届的新人,对nginx理解不是很深入,非常感谢大家的帮助。
1 回答

犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
本地和nginx环境访问的文件目录是不一样的。
服务器上是把build之后的文件放在类似 abc/ 目录下,我们访问的是这些
所以在nginx上配置应该类似于这样写法:
location /abc.html { alias /opt/abc/abc.html; try_files $uri $uri/ /abc/abc.html; } location /def.html { alias /opt/abc/def.html; try_files $uri $uri/ /abc/def.html; }
配置完nginx配置文件后,nginx -t ,测试没有问题,在nginx -s reload重启下nginx服务。
添加回答
举报
0/150
提交
取消