【发布时间】:2016-03-20 10:22:26
【问题描述】:
我正在尝试在 elasticsearch 上启用 CORS,以便可以从 Angular 应用程序访问它。
我正在添加
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length
到 elasticsearch.yml 文件的底部。然后我重新启动了 elasticsearch 服务,但在我的日志文件中它显示节点正在停止、停止、关闭、关闭,但它永远不会重新启动。
如果我进入我的 elasticsearch.yml 并删除或注释掉上面的行,然后重新启动 elasticsearch.yml,elasticsearch 将重新启动正常。
所以我不确定我做错了什么。
这些行是从我本地安装的 elasticsearch 复制的,但它在 OSX 上运行。我不确定操作系统是 Ubuntu 14.04 时是否有一些细微差别。
根据我在elasticsearch.js client connection refused: Access-Control-Allow-Origin not recognized? 找到的内容,这就是我的 .yml 文件现在的样子:
http.cors.enabled : true //
http.cors.allow-origin: "/.*/"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization"
【问题讨论】:
-
您可以尝试删除属性名称和冒号之间的空格吗?您还需要将方法和标头用双引号括起来。
-
我已经完成了这些并重新启动,我得到了同样的东西。 Elasticsearch 一直处于关闭状态。当我注释掉这些行时,ES 重新启动并运行。
标签: angularjs elasticsearch ubuntu-14.04