且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

elasticsearch.js客户端连接被拒绝:访问控制允许来源不承认?

更新时间:2023-12-01 20:36:28

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

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>

每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 电话。