2016-04-28 165 views
0

我正在使用elasticsearch的2.3.2版本。在我的elasticsearch.yml文件中,我添加了以下几行以允许跨源请求。elasticsearch:尽管配置http模块,跨源请求被阻止

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

更换​​参数与"*",似乎工作,但文件表明,这是一个安全的请求。

来自浏览器的请求标题如下;

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 

有人可以请建议我在做什么错误在上面?

+0

可以尝试把它写在双引号? – alpert

+0

如果添加双引号,elasticsearch将无法启动。 – JSB

回答

0

你似乎有一个小的错字。

它应该阅读

http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/ 
          ^
          | 
          add this 

即您的?,这意味着之前缺少s“HTTP或HTTPS”

+0

嗨缬氨酸 - 我确实已经尝试过 - 实际上似乎没有什么改变。 – JSB

+0

我怀疑查询不是来自本地主机,但可能是127.0.0.1,这可能吗?你可以在发送查询时检查你在Firefox开发者工具中看到的内容吗?请求者使用什么主机? – Val

+0

添加上面的reqeuste标题 - 似乎使用本地主机。也尝试在yml文件中使用127.0.0.1,但也不好。 – JSB

相关问题