elasticsearch.js客户端连接被拒绝:访问控制允许来源不承认? [英] elasticsearch.js client connection refused: Access-Control-Allow-Origin not recognized?

查看:1209
本文介绍了elasticsearch.js客户端连接被拒绝:访问控制允许来源不承认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用elasticsearch.jquery.min.js ping一个本地运行elasticsearch每次我得到一个没有生活连接的错误。

I've been trying to ping a locally running elasticsearch using elasticsearch.jquery.min.js and I get a "no living connection" error each time.

ETA:在Chrome中我看到什么样子了pretty低水平拒绝连接。我开发在MacOS X和我的浏览器,透过 HTTP页面指向://本地主机/〜myuserid /网站名称/ 。当我访问本地主机:9200 这下跨域CORS要求显然属于

ETA: In Chrome I see what looks like a pretty low level "Connection Refused". I'm developing on MacOS X, and my browser points at the page via http://localhost/~myuserid/SiteName/. As I'm accessing localhost:9200 this clearly falls under cross domain CORS requirements.

我看到下面的错误在Chrome控制台:

I see the following error in the Chrome console:

XMLHttpRequest cannot load http://localhost:9200/?hello=elasticsearch!.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.

http://enable-cors.org/server_apache.html 我添加以下为/etc/apache2/httpd.conf:

Per http://enable-cors.org/server_apache.html I've added the following to /etc/apache2/httpd.conf:

<Directory />
    Header set Access-Control-Allow-Origin "localhost:9200"
    AllowOverride none
    Require all denied
</Directory>

和运行

$ sudo apachectl -t
$ sudo apachectl -k graceful

但错误依然存在。有我俯瞰另一个设置?

but the error persists. Is there another setting I'm overlooking?

我对elasticsearch.js一个小白。有什么我需要做的elasticsearch方允许从浏览器,或一些客户端连接?

I'm a noob to elasticsearch.js. Is there anything I need to do on the elasticsearch side to allow client connections from the browser, or something?

我在下面的在我的ping尝试:

I'm following the book in my ping attempt:

var client = new $.es.Client({
  hosts: 'localhost:9200'
  });

client.ping(
  {
    requestTimeout: Infinity,
    // undocumented params are appended to the query string
    hello: "elasticsearch!"
    },
  function (error) {
    if (error) {
      console.error('elasticsearch cluster is down!');
      console.error(error);
    } else {
      console.log('All is well');
      }
    }
  );

但我发现了以下错误(S):

but I'm getting the following error(s):

"WARNING: 2015-10-10T07:00:16Z"        elasticsearch.jquery.min.js:14:10575
  Unable to revive connection: http://localhost:9200/

"WARNING: 2015-10-10T07:00:16Z"        elasticsearch.jquery.min.js:14:10575
  No living connections

我可以连接使用命令行就好上的卷曲,拉和插入数据等。

I can connect using curl on the command line just fine, pull and insert data, etc.:

$ curl "localhost:9200/_cat/indices?v"
health status index             pri rep docs.count docs.deleted store.size pri.store.size 

green  open   fuddle              1   0          3            0     12.9kb         12.9kb                                                
green  open   faddle              1   0          0            0       144b           144b 





ETA附加诊断。谷歌浏览器显示了失败的尝试以下网络痕迹。在HTTP层的响应看起来像它的发生。

ETA additional diagnostics. Google Chrome shows the following network traces for the failing attempt. At the HTTP layer the response looks like it's happening.

General
  Remote Address:[::1]:9200
  Request URL:http://localhost:9200/?hello=elasticsearch!
  Request Method:HEAD
  Status Code:200 OK
Response Headers
  Content-Length:0
  Content-Type:text/plain; charset=UTF-8
Request Headers
  Accept:text/plain, */*; q=0.01
  Accept-Encoding:gzip, deflate, sdch
  Accept-Language:en-US,en;q=0.8
  Connection:keep-alive
  Content-Length:0
  Host:localhost:9200
  Origin:http://localhost
  Referer:http://localhost/~browsc3/Opticon/
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Query String Parameters
  view URL encoded
  hello:elasticsearch!

在wget的同一请求:

The same request in wget:

wget http://localhost:9200/?hello=elasticsearch!
--2015-10-10 09:47:13--  http://localhost:9200/?hello=elasticsearch!
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:9200... connected.
HTTP request sent, awaiting response... 200 OK
Length: 342 [application/json]
Saving to: 'index.html?hello=elasticsearch!'

index.html?hello=elastics 100%[=====================================>]     342  --.-KB/s   in 0s     

2015-10-10 09:47:13 (65.2 MB/s) - 'index.html?hello=elasticsearch!' saved [342/342]

我真的很茫然哪里何去何从。我看到很多引用对德googlz错误,但没有的情况下,似乎远程相似。这感觉就像我只是打了一些错误配置,但我找不到任何可以表明那是什么。

I'm really at a loss where to go from here. I see lots of references to the error on teh googlz, but none of the circumstances seem remotely similar. It feels like I'm just hitting some misconfiguration, but I can't find anything that would indicate what that is.

推荐答案

嗯,这是一个艰难的一个。

Well, that was a tough one.

下面就是固定它:

,http://enable-cors.org/server_apache.html 在 /等/ apache2的/ httpd.conf文件,配置访问控制允许来源:

Per http://enable-cors.org/server_apache.html, in /etc/apache2/httpd.conf, configure Access-Control-Allow-Origin:

<Directory />
    # Add the following line to enable CORS to connect to local elasticsearch.
    Header set Access-Control-Allow-Origin "localhost:9200"
    AllowOverride none
    Require all denied
</Directory>

每<一个href=\"https://jsbroadcast.com/elastic-search-cors/\">https://jsbroadcast.com/elastic-search-cors/,在 elasticsearch-1.7.0 /配置/ 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, Authorization"

我现在可以运行没有任何错误的 client.ping 电话。

这篇关于elasticsearch.js客户端连接被拒绝:访问控制允许来源不承认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆