Nginx部署的VueJS打包后的文件,刷新后提示404
导言
在Linux/CentOS中,使用
Nginx
部署VueJS
打包后的文件,在非根路由的页面,刷新后显示404是因为未找到对应的html
文件,VueJS
是根据Vue-Router
匹配对应的文件,然后做呈现。若未对Nginx
进行对应的配置的话,刷新后由于找不到对应的html
文件,所以会出现404的问题
配置nginx.conf
server {
listen 80;
listen [::]:80;
server_name _;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location / {
root <html文件夹的完整路径信息>;
try_files $uri $uri/ /index.html;
}
location = /404.html {
}
location /api {
proxy_pass http://127.0.0.1:3002;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
重启Nginx
nginx -s reload
上一篇:
没有了
下一篇:
没有了