【问题标题】:Elasticsearch CORS HTTPD and AngularJs Communication IssueElasticsearch CORS HTTPD 和 AngularJs 通信问题
【发布时间】:2016-07-28 11:04:36
【问题描述】:

我正在使用 Elasticsearch 来存储和查询日志。我正在创建一个前端 UI,它将使用 AngularJs 将来自 Elasticsearch 的查询信息显示到网页。该网页在端口 80 上的 CentOS 6 Apache HTTPD 上运行。Elasticsearch 在端口 9200 上运行。当我使用 AngularJs 查询 Elasticsearch 时,出现以下错误:

XMLHttpRequest cannot load http://my_ip/ali_viewer/log/_search. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

这似乎是在 stackoverflow 和其他网络上发现的常见问题,但是在尝试了这么多解决方案但没有成功后,我将发布我的具体配置。

httpd.conf

<Directory />
    Header set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type"
    Options FollowSymLinks
    AllowOverride None
</Directory>

elasticsearch.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

有谁知道为什么这不起作用?

【问题讨论】:

    标签: apache elasticsearch cors


    【解决方案1】:

    More robust handling of CORS HTTP Access Control #16436

    这是2.3.1版本的问题,你可以使用nginx做反向代理来解决这个问题。

    【讨论】:

      猜你喜欢
      • 2013-11-20
      • 2017-06-14
      • 2013-07-19
      • 2017-02-24
      • 1970-01-01
      • 2018-05-19
      • 2015-04-17
      • 2016-08-24
      • 2014-02-28
      相关资源
      最近更新 更多