Elasticsearch CORS HTTPD和AngularJs通信问题

时间:2016-04-07 13:54:00

标签: apache elasticsearch cors

我使用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

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

1 个答案:

答案 0 :(得分:0)

More robust handling of CORS HTTP Access Control #16436

这是版本2.3.1中的问题,您可以使用nginx作为反向代理来解决此问题。