【问题标题】:How to setup elasticsearch secure connection using HTTPS through REST API如何通过 REST API 使用 HTTPS 设置 elasticsearch 安全连接
【发布时间】:2017-05-23 08:20:29
【问题描述】:

我想在 Lucene 引擎中查询由 elasticsearch 索引的数据,但我希望通过使用 SSL 来确保此连接的安全:

https://x.y.z.w:9200/index_name/_search?&q=field:value

这是我的全部代码:

<!doctype html>
<html lang="fa">
   <head>
    <title>XHR App Test</title>
    <script>
       function send() {
            var xhr = new XMLHttpRequest(),
            url = 'https://x.y.z.w:9200/index_name/_search?&q=field:value',
            sendButton = document.getElementById('sendButton');

        xhr.onreadystatechange = function(e) { 
            console.log(e);
            if (e.currentTarget.readyState > 2) {
                document.getElementById('result').innerHTML = e.currentTarget.responseText;
            }
        };
        xhr.open('GET', url, true);
        xhr.send(null);
    }
    </script>
  </head>
  <body>
     <h1>XHR App Test</h1>

     <button id='sendButton' onclick="send()">Send</button>
     <div id="result"></div>

  </body>
</html>

我还在elasticsearch.yml 文件中添加了这些配置:

 http.port: 9200
 http.cors.enabled : true
 http.cors.allow-origin: /https?:\/\//
 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"
# http.cors.allow-credentials : true

但是只能通过http协议而不是https来查询。

如何解决?

【问题讨论】:

标签: rest elasticsearch lucene


【解决方案1】:

Elasticsearch 不支持开箱即用的 SSL。 http.cors 设置用于启用和设置CORS(跨域资源共享)机制,但与 SSL 无关。

如果您希望 ES 集群通过 HTTPS/SSL 处理请求,则需要使用 Shield plugin 设置 SSL/TLS,如果您正在运行 ES 5,最好使用 XPack

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 2018-09-22
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    相关资源
    最近更新 更多