0

elasticsearch-head 不能连接管理elasticsearch

final created at6 years ago view count: 15398

命令行运行grunt server

grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

打开http://localhost:9100进入管理页面, 填写好地址点连接, 然后连接不上elasticsearch , 浏览器错误详情提示不安全

Firefox Console: 已拦截跨源请求:同源策略禁止读取位于 http://localhost:9200/ 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。

Chrome Console: XMLHttpRequest cannot load http://localhost:9200/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9100' is therefore not allowed access.

report
回复
0

因为端口不一样, 所以浏览器自带的安全策略是不允许去请求不同源的资源。

修改Elasticsearch配置

elasticsearch.yml 添加下面配置,重启后即可生效

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
6 years ago 回复
0
neo #
when in doubt, use brute force

可以用 Nginx 做下反代, 然后加下Header。然后地址改为http://localhost:9201

server {
    listen   9201;
    location ~ /* {
        add_header Access-Control-Allow-Origin *;
        proxy_pass http://127.0.0.1:9200;
    }
 }
6 years ago 回复
0

之前也是碰到楼主上面的问题,跨域问题~ 修改elasticsearch 的 elasticsearch.yml 文件后解决,版本都是5.x 版本~

http.host: 192.168.x.x (elasticsearch 的ip 一般 elasticsearch 和 head 是同一台上面~) http.cors.enabled: true http.cors.allow-origin: "*"

6 years ago 回复
0

因为都是内网的IP所以还是http.cors.allow-origin: "*"简单暴力好用

6 years ago 回复

Recent search keywords