nginx部署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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章