NGinx + Elasticsearch + HTTP keepalive

We have setup several small clusters and are noticing strange HTTP keepalive behavior. My understanding is that keepalive in NGinx should keep the given number of connections open to the backend ES cluster. Unfortunately, we see lots of other values for open connections, but never the one we set.

In this scenario, we have nginx on the same server as ES, but the problem exists across all of our clusters, regardless.


http: {
current_open: 1,
total_opened: 612

In our nginx config, we have the following:

events {
        worker_connections 1024;

http {

        upstream elasticsearch {
                keepalive 15;

        server {
                listen 80;

                location / {
                        proxy_pass http://elasticsearch;
                        proxy_redirect off;

                        proxy_set_header  X-Real-IP  $remote_addr;
                        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header  Host $http_host;

                        proxy_http_version 1.1;
                        proxy_set_header Connection "Keep-Alive";
                        proxy_set_header Proxy-Connection "Keep-Alive";
                        proxy_set_header Access-Control-Allow-Origin *;

                        proxy_pass_header Access-Control-Allow-Origin;
                        proxy_pass_header Access-Control-Allow-Methods;
                        proxy_hide_header Access-Control-Allow-Headers;

                        add_header Access-Control-Allow-Credentials true;
                        add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type';

                        auth_basic "Restricted";
                        auth_basic_user_file /etc/nginx/.htpasswd;

Any help would be appreciated. http.enabled and network.tcp.keepalive are both set to true in the elasticsearch config, also.

Is it causing issues or are you just wanting to understand the differences?

The worry is that it may end up causing issues, if the 15 keepalive setting isn't sticking. Having a connection open/close over and over again, defeats the purpose of the setting.

HTTP Keep-alive does not mean persistent connection. After a timeout, connection will be closed if idle. The keep-alive timeout setting for nginx is 75 seconds: