dbblog icon indicating copy to clipboard operation
dbblog copied to clipboard

前台用nginx作为服务器路由问题

Open Lang-Zh opened this issue 5 years ago • 4 comments

前台我使用webpack打包后使用用nginx作为服务器 ,好像因为前台不像后台使用的前端路由 ,只有首页有效 跳转其他页面都会有问题 请问要怎么处理

Lang-Zh avatar Aug 11 '19 03:08 Lang-Zh

因为我的路由是histroy模式,nginx需要配 try_files $uri $uri/ /index.html; 如下:

server { listen 80; server_name dblearn.cn www.dblearn.cn; location / { root /home/bobbi/deploy/dbblog/dbblog-frontend/dist; try_files $uri $uri/ /index.html; index index.html index.htm; } }

llldddbbb avatar Aug 17 '19 03:08 llldddbbb

vue官网回答如下:https://router.vuejs.org/zh/guide/essentials/history-mode.html

llldddbbb avatar Aug 17 '19 03:08 llldddbbb

谢谢大佬 已解决

Lang-Zh avatar Aug 17 '19 05:08 Lang-Zh

因为我的路由是histroy模式,nginx需要配 try_files $uri $uri/ /index.html; 如下:

server { listen 80; server_name dblearn.cn www.dblearn.cn; location / { root /home/bobbi/deploy/dbblog/dbblog-frontend/dist; try_files $uri $uri/ /index.html; index index.html index.htm; } }

能看一下nginx完整的配置吗 nginx的配置搞不定

ruiyeclub avatar Jul 10 '20 02:07 ruiyeclub