elasticsearch.js client connection refused: Access-Control-Allow-Origin not recognized?

前端 未结 3 1021
长情又很酷
长情又很酷 2021-02-09 23:54

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: In Chrome I

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 00:03

    Well, that was a tough one.

    Here's what fixed it:

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

    
        # 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
    
    

    Per https://jsbroadcast.com/elastic-search-cors/, in elasticsearch-1.7.0/config/elasticsearch.yml add:

    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"
    

    I can now run the client.ping call without any error.

提交回复
热议问题