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.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...