【发布时间】: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