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

前端 未结 3 1022
长情又很酷
长情又很酷 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:

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

    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.

    0 讨论(0)
  • 2021-02-10 00:08

    Just adding this to elasticsearch.yml should work.

    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"
    

    You don't need to add anything to Apache.

    0 讨论(0)
  • 2021-02-10 00:15

    Put in your elasticsearch.yml configuration file, located in elasticsearch-xxx\config\elasticsearch.yml, the line below

    http.cors.enabled: true
    

    and Enable cors in your internet navigator. Restart you elasticsearch server and try again.

    0 讨论(0)
提交回复
热议问题