vue打包部署访问页面的问题

在通过nginx启动vue以后我们在访问页面的时候只能访问默认页面和通过项目内跳转其他页面,如果刷新就会404

 

可以看到nginx并不识别vue的其他页面,这跟conf文件的配置有关

location / {
root /home/nx/dist;
index index.html index.htm index.jsp;
}
这是我们基础的配置,按照字义解读就是只访问了/dist文件下的  index.html、index.htm、index.jsp页面,而其他页面在访问的时候被nginx当作自身的服务访问而找不到,我们修改一下配置文件

location / {
root /home/nx/dist;
#index index.html index.htm index.jsp;
#proxy_pass http://admin;
#proxy_redirect default;
#proxy_connect_timeout 10;
try_files $uri $uri/ /index.html;
expires 7d;
}
将默认的index注释掉,换成了try_files,它会去扫描内部目录然后再进行内部重定向。

nginx的try_files:https://www.cnblogs.com/boundless-sky/p/9459775.html

expires 是nginx控制缓存的一种方式,7d=7天

nginx配置expires:https://blog.csdn.net/hjh15827475896/article/details/53434298
————————————————
版权声明:本文为CSDN博主「余生大大」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/AnNanDu/article/details/105215592

posted @ 2021-04-22 16:05  伟仔技术博客  阅读(628)  评论(0编辑  收藏  举报