nginx - Elasticsearch : Connection refused while connecting to upstream

标签 nginx elasticsearch kibana

我已经使用 Kibana 设置了一个 Elasticsearch 服务器来收集一些日志。

Elasticsearch 在 Nginx 的反向代理后面,这里是 conf :

server {   
  listen   8080;   
  server_name myserver.com; 
  error_log   /var/log/nginx/elasticsearch.proxy.error.log;
  access_log  off;

  location / {

    # Deny Nodes Shutdown API
    if ($request_filename ~ "_shutdown") {
      return 403;
      break;
    }

    # Pass requests to ElasticSearch
    proxy_pass http://localhost:9200;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";

    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;

    # For CORS Ajax
    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-Headers 'X-Requested-With, Content-Type';
    add_header Access-Control-Allow-Credentials true;

  }

}

一切正常,我可以curl -XGET "myserver.com:8080" 来检查,然后我的日志就进来了。

但每隔一分钟左右,在 nginx 错误日志中,我会得到:

2014/05/28 12:55:45 [error] 27007#0: *396 connect() failed (111: Connection refused) while connecting to upstream, client: [REDACTED_IP], server: myserver.com, request: "POST /_bulk?replication=sync HTTP/1.1", upstream: "http://[::1]:9200/_bulk?replication=sync", host: "myserver.com"

我不知道它是什么,conf 中是否有任何问题会阻止某些 _bulk 请求通过?

最佳答案

似乎 upstream 和不同的 keepalive 是 ES 后端正常工作所必需的,我终于使用以下配置让它工作了:

upstream elasticsearch {
    server 127.0.0.1:9200;
    keepalive 64;
}

server {

  listen 8080;
  server_name myserver.com;
  error_log   /var/log/nginx/elasticsearch.proxy.error.log;
  access_log  off;

  location / {

    # Deny Nodes Shutdown API
    if ($request_filename ~ "_shutdown") {
      return 403;
      break;
    }

    # Pass requests to ElasticSearch
    proxy_pass http://elasticsearch;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";

    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;

    # For CORS Ajax
    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-Headers 'X-Requested-With, Content-Type';
    add_header Access-Control-Allow-Credentials true;

  }

}

关于nginx - Elasticsearch : Connection refused while connecting to upstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909960/

相关文章:

nginx - Phusion Passenger 配置文件在哪里?

node.js - nginx/sails.js : incomplete file upload

node.js - Nodejs http2 落后于(nginx 或其他网络服务器)与 Nodejs 中的推送

go - ElasticClient Olivere 包维护与先前部署的 ECS 集群的长期连接

elasticsearch - 如何使 Elasticsearch 评分考虑字段长度

elasticsearch - 脚本字段未出现在Kibana的可视化中

laravel - Nginx 上历史模式的 Vue 路由器服务器配置不起作用

elasticsearch - 将参数传递给Liferay的服务搜索功能

elasticsearch - 计算事件之间的时间

elasticsearch - Kibana 返回 "Connection Failed"