请教 nginx 配置 vue 的问题

2017-10-07 22:39:57 +08:00
 gogobody

问题:

访问 http://xx/landf/ 正常

访问 http://xx/landf/index.html 没有渲染

访问 http://xx/others 没有渲染

在 vue 中点击链接跳转正常,直接输入 vue 路由链接 没有渲染

配置参考的网上的。。。 请问这是什么原因呢?

nginx 配置如下:

        location /landf/ {
                root /home/ubuntu/python/lost_found/web/;
                index index.html index.htm;

        }
        location / {
                try_files $uri $uri/ /landf/index.html;
                index index.html;
        }

5184 次点击
所在节点    Vue.js
15 条回复
Pastsong
2017-10-07 22:45:12 +08:00
vue 这种框架在后端只有一个入口(除 ssr ),所有路径都返回 index.html 就好了
gogobody
2017-10-07 22:46:21 +08:00
@Pastsong nginx 第二条不是这个意思嘛。。。
Trim21
2017-10-07 23:19:48 +08:00
@gogobody 不是,是先请求$uri $uri/
Trim21
2017-10-07 23:20:00 +08:00
try_files /landf/index.html;
gogobody
2017-10-07 23:49:14 +08:00
@Trim21 这样写 给了一个错 nginx: [emerg] invalid number of arguments in "try_files" directive in /etc/nginx/conf.d/lostandfound.conf:26
Trim21
2017-10-08 00:44:54 +08:00
@gogobody 啊啊啊啊抱歉说错了

访问 http://xx/others 没有渲染是因为 index.html 请求成功,但是 /static/文件夹里的 js,css 之类的请求失败了


其实不需要配置 landf 那一项,直接这样

location / {
root /home/ubuntu/python/lost_found/web/;
index index.html;
try_files $uri $uri/ /index.html;
}
Trim21
2017-10-08 01:01:12 +08:00
root /home/ubuntu/python/lost_found/web/landf/;
gogobody
2017-10-08 01:03:21 +08:00
@Trim21 感谢,已经关了电脑了,明天再试试,主要是我想把配置在 /land/路径下,而不是根路径
Trim21
2017-10-08 01:05:47 +08:00
@gogobody 你用的是 history 模式吗..
gogobody
2017-10-08 01:23:19 +08:00
@Trim21 是的!
Trim21
2017-10-08 01:32:45 +08:00
@gogobody 感觉 history 模式挂载在目录下挺蛋疼的...要自己手动在 path 前面都加上路径
是不是我姿势不太对...有什么相应的设置吗
Trim21
2017-10-08 01:39:41 +08:00
@Trim21
有点词不达意...原来在 vue-router 里面设置了 path:"/index"为了挂载到 sub 目录下面好像只能手动改成 path:"/sub/index.."
gogobody
2017-10-08 01:46:40 +08:00
@Trim21 我是看了 https://www.zhihu.com/question/46630687 这个二楼配置的,不知道为什么效果不一样
Trim21
2017-10-08 02:06:49 +08:00
@gogobody 谢谢老哥...
他没牵扯到在两个路径部署同一个 app 的情况..
gogobody
2017-10-08 10:45:20 +08:00
@Trim21 大神可以留个联系方式不

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/395850

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX