I am setting up a nginx reverse proxy for ElasticSearch (with HTTP Basic Auth) as described in this article.

This is my nginx config file:

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";

The proxy correctly forwards port 8080 to 9200, and is supposed to keep persistent connections (keepalive) to Elasticsearch.

This is the result of visiting either the URL http://elasticsearch.example.org:9200/_nodes/stats/http?pretty or http://elasticsearch.example.org:8080/_nodes/stats/http?pretty (HTTP authentication has already been done) in a browser:

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

When visiting the page on port 9200 (direct connection to Elasticsearch) and reloading, the field total_opened is supposed to increase, while when visiting on port 8080 (through the nginx proxy) and reloading, the field should not change.

In fact, it happens the opposite. What is the reason of this strange behavior?

1 Answer 1


You have defined an upstream container called elasticsearch. But you do not invoke it. Try replacing your proxy_pass directive with:

proxy_pass http://elasticsearch;

See this document for details.

  • It seems you're right. This is the setting that I was using at the beginning but I changed it as it was returning a 502 Bad Gateway error. Then it means there was something else causing that 502 error. Now keepalive works -- but, strangely, it works on port 9200 as well as 8080. Any explanations for this?
    – dr_
    Commented Feb 23, 2016 at 13:24
  • Ok, I've been running some tests and the problem is solved. The behavior above appears when using Firefox because this browser enforces persistent connections. When fetching the URL via wget (wget http://elasticsearch.example.org:9200/_nodes/stats/http?pretty -O -) it works as it should be: on port 9200 the value of total_opened increases, while on port 8080 it does not (the keepalive mechanism is active). Thanks a lot.
    – dr_
    Commented Mar 3, 2016 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .