错误图片
第一种方法(本人亲测):
可以看到nginx并不识别vue的其他页面
原因:这是我们基础的配置,按照字义解读就是只访问了/dist文件下的 index.html、index.htm页面,而其他页面在访问的时候被nginx当作自身的服务访问而找不到
conf文件的配置:
解决:在server里面添加两行代码:
try_files $uri /index.html;
expires 7d;
原因:
加上try_file它会去扫描内部目录然后再进行内部重定向。
expires 是nginx控制缓存的一种方式,7d=7天
完成之后
第二种方法:
和第一种方法相似,都是修改nginx中conf配置文件,只修改的地方不同。
location / {
root D:/nginx-1.18.0/html/dist;
index index.html index.htm;
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}