vue部署docker下的nginx刷新404

部署到nginx,访问首页没问题,从首页里跳转其他页面也没问题,但是非首页的其他页面,再次刷新,就会出现404现象。

Dockerfile
'# 使用官方镜像,官方镜像比较纯净,没有curl等网络工具,需要安装网络工具需要自己构建nginx镜像
FROM nginx
'# 将你的打包目录(h5)拷贝到 nginx镜像指定目录中
COPY h5/ /usr/share/nginx/html/
'# 将自定义的配置文件覆盖默认的配置文件
COPY default.conf /etc/nginx/conf.d/default.conf
'# 暴露80端口
EXPOSE 80

default.conf

server {
location / {
root /usr/share/nginx/html/;
index index.html;
try_files $uri $uri/ /index.html;
}
}

个人理解:$ uri表示访问的页面,$uri/表示配置的根路径,如果路径下没有,则跳转到根路径下的/index.html

猜你喜欢

转载自blog.csdn.net/m0_46269902/article/details/106526662