【发布时间】:2016-08-22 18:51:58
【问题描述】:
我使用的是 2.3.2 版的 elasticsearch。在我的 elasticsearch.yml 文件中,我添加了以下几行以允许跨域请求。
http.cors.enabled: true
http.cors.allow-credentials: true
http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE
http.cors.max-age: 0
http.cors.allow-origin: /http?:\/\/localhost(:[0-9]+)?/
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length
但是,当我尝试从 Firefox 执行查询时,出现以下错误;
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at http://localhost:9200/someIndex/_search?size=10&from=0.
(Reason: CORS header 'Access-Control-Allow-Origin' missing).
用"*" 替换http.cors.allow-origin 参数似乎可行,但文档表明这是一个安全请求。
来自浏览器的请求标头如下;
Accept - application/json, text/plain, */*
Accept-Encoding - gzip, deflate
Accept-Language - en-US,en;q=0.5
Content-Length - 26
Content-Type - application/json;charset=utf-8
DNT - 1
Host - localhost:9200
Origin - null
User-Agent - Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0
有人可以建议我在上面做错了什么吗?
【问题讨论】:
-
你能试着用双引号写吗?
-
如果添加双引号,elasticsearch 将无法启动。
标签: elasticsearch cors