之前一直忽视了这个问题,直接导致taiga-front的部署的时候不能通过其他IP访问。
如图:
首先是提示
app-loader.js:1 Your conf.json file is not a valid json file, please review it.
这样导致用默认的conf 也就是后面那句:
Failed to load resource: net:localhost:8000/api/v1/stats/discover Failed to load :ERR_CONNECTION_REFUSED
现在因为部署版本的conf.json读取失败(因为注释的原因),导致加载了默认的开发时配置。默认的conf.json:
{ ???"api": "http://localhost:8000/api/v1/", ???"eventsUrl": null, ???"eventsMaxMissedHeartbeats": 5, ???"eventsHeartbeatIntervalTime": 60000, ???"debug": true, ???"debugInfo": false, ???"defaultLanguage": "en", ???"themes": ["taiga"], ???"defaultTheme": "taiga", ???"publicRegisterEnabled": true, ???"feedbackEnabled": true, ???"privacyPolicyUrl": null, ???"termsOfServiceUrl": null, ???"maxUploadFileSize": null, ???"contribPlugins": []}
而部署版的conf.json:
{ ???"api": "http://192.168.1.152/api/v1/", ???"eventsUrl": "ws://192.168.1.152/events", ???"debug": true, ???"publicRegisterEnabled": true, ???"feedbackEnabled": true, ???"privacyPolicyUrl": null, ???"termsOfServiceUrl": null, ???"maxUploadFileSize": null, ???"contribPlugins": []}
最大的区别就是后端api 的地址
localhost:8000。相当于本机开发前端,在本机起后端。
而部署时,这里是要替换成域名或主机IP的。
1客户机访问 ip地址(80端口)
2nginx相应请求,跳转的taiga-frontend
3frontend对后端发起请求,即调用ip地址/api/...
4前端节点的nginx根据后面的/api 做反代,才转到内网后端IP:端口/api/...上
那么如果用默认conf.json从外网访问,没有访问taiga主机的IP,而是去找客户机的localhost:8000,直接导致无法注册、跳转(直接卡死在首页上)
——其实,taiga这样设计也有问题,第3步,按说应该完全封装内网不应该找不到,不应该再从客户端看见这种报错了。
——解决方案:老实把注释删了,留下11行的json
心得:不要想当然,要相信报错。
自己用pyhon的json.load() 读一下conf.json,就确认无疑了,再去上网查一下,就确认问题了。
直接用报错信息搜索,是搜不到答案的。(也许恰恰是自己太弱智了,别人都没遇到)。
——后记,之后还时报这个错,发现另外一个问题:
frontend 复制配置文件在 COPY或-v挂源代码之前了。这样根据docker image的堆叠机制,导致conf.json被覆盖(没有)
源码的配置文件,是源码的一部分,在外面生成好,一起挂进去,OK
json文件不能有注释
原文地址:http://www.cnblogs.com/xuanmanstein/p/8017938.html