微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

keepalive的相反行为(在ElasticSearch上使用nginx反向代理)

我正在为ElasticSearch(使用HTTP Basic Auth)设置一个Nginx反向代理,如in this article所述.

这是我的Nginx配置文件

events {
        worker_connections  1024;
}


http {
        upstream elasticsearch {
                server elasticsearch.example.org:9200;
                keepalive 64;
        }

        server {
                listen 8080;

                location / {
                        auth_basic "ElasticSearch";
                        auth_basic_user_file /var/www/.htpasswd;

                        proxy_pass http://elasticsearch.example.org:9200;
                        proxy_http_version 1.1;
                        proxy_set_header Connection "Keep-Alive";
                        proxy_set_header Proxy-Connection "Keep-Alive";
                }
        }
}

代理正确地将端口8080转发到9200,并且应该保持与Elasticsearch的持久连接(keepalive).

这是在浏览器中访问URL http://elasticsearch.example.org:9200/_nodes/stats/http?prettyhttp://elasticsearch.example.org:8080/_nodes/stats/http?pretty(已经完成HTTP身份验证)的结果:

{
  "cluster_name" : "elasticsearch",
  "nodes" : {
    "rIFmzNwsRvGp8kipbcwajw" : {
      "timestamp" : 1455899085319,
      "name" : "Kid Colt",
      "transport_address" : "elasticsearch.example.org/10.3.3.3:9300",
      "host" : "10.3.3.3",
      "ip" : [ "elasticsearch.example.org/10.3.3.3:9300", "NONE" ],
      "http" : {
        "current_open" : 3,
        "total_opened" : 28
      }
    }
  }
}

当访问端口9200上的页面(直接连接到Elasticsearch)并重新加载时,字段total_opened应该增加,而当访问端口8080(通过Nginx代理)并重新加载时,字段不应该改变.

事实上,恰恰相反.这种奇怪行为的原因是什么?

解决方法:

您已经定义了一个名为elasticsearch的上游容器.但是你没有调用它.尝试将proxy_pass指令替换为:

proxy_pass http://elasticsearch;

有关详情,请参见this document.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐