Elasticsearch 404 嘗試透過 nginx 代理程式建立索引

Elasticsearch 404 嘗試透過 nginx 代理程式建立索引

我正在嘗試透過 nginx 代理 Elasticsearch。大多數事情似乎都有效,但有問題的一件事是建立索引。

這在直接連接到 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

但是當我嘗試將 nginx 作為 ES 前面的代理時,我從 ES 得到了 404。我的 nginx 設定是:

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 設定為偵聽 IP 位址,因此我認為這與未傳遞主機標頭無關:

# elasticsearch.yml
network.bind_host: 127.0.0.2

這感覺像是 ES 的一些挑剔,但也許我對 nginx 代理做了一些愚蠢和錯誤的事情。我不太確定還能嘗試什麼。我見過一些相關的問題,解決方案是不使用 nginx,但這對我來說並不是一個真正的選擇。

nginx 1.14,elasticsearch 1.7。

答案1

請看一下https://www.nginx.com/blog/nginx-elasticsearch-better-together/#proxy_cache_valid

特別是下面的參數。

    proxy_cache elasticsearch;
    proxy_cache_valid 200 302 10m;
    proxy_cache_valid 404 1m;

相關內容