0

I am attempting to proxy Elasticsearch through nginx. Most things seem to work, but one thing that is having problems is creating indexes.

This works when connecting directly to ES:

curl -XPUT http://localhost:9200/foo" -fsS -o/dev/null -d@- << BODY
{
  "settings": {
    "analysis": {
      "analyzer": {
        "case_insensitive_sort": {
          "tokenizer": "keyword",
          "filter": ["lowercase"]
        }
      }
    },
    "index": {
      "number_of_replicas": 0
    }
  }
}
BODY

But when I try to put nginx up as a proxy in front of ES, I get a 404 from ES. My nginx config is:

upstream es {
  server 127.0.0.2:9200;
}

map $request_method $upstream {
  default es;
}

server {
  listen 127.0.0.1:9200;
  client_max_body_size 20M;

  location / {
    proxy_pass http://$upstream;
  }
}

ES is setup to listen on an IP address, so I don't think this is related to host headers not being passed:

# elasticsearch.yml
network.bind_host: 127.0.0.2

This feels like something finicky about ES, but maybe I'm doing something dumb and wrong with the nginx proxy. I'm not really sure what else to try. I've seen some related issues where the solution was to not use nginx, but that's not really an option for me.

nginx 1.14, elasticsearch 1.7.

rich remer
  • 449
  • 4
  • 11

1 Answers1

0

Please have a look on https://www.nginx.com/blog/nginx-elasticsearch-better-together/#proxy_cache_valid

specially below parameters.

    proxy_cache elasticsearch;
    proxy_cache_valid 200 302 10m;
    proxy_cache_valid 404 1m;
asktyagi
  • 2,401
  • 1
  • 5
  • 19