有时来自api服务器的响应json被截断

时间:2018-03-22 10:33:10

标签: nginx

环境

(request) -> (ALB) -> rails(unicorn) - (API) -> (ALB) -> nginx -> java server(tomcat)

nginx 1.13.0,Apache Tomcat / 8.5.16

WHAT

有时独角兽会收到截断的json。 同时,在nginx上发生错误。

2018/03/19 19:17:01 [error] 11#11: *234263 readv() failed
(104: Connection reset by peer) while reading upstream, client: xxx.xxx.xx.x, server: _, 
request: "GET /some_endpoint HTTP/1.1", upstream: "http://xxx.xxx.xx.x:8080/some_endpoint", 
host: "xxx.ap-northeast-1.elb.amazonaws.com"

我用Google搜索了一些nginx truncated jsonConnection reset by peer while reading upstream,但我没有得到任何信息。

作为每个关联,响应json有点大(低于64kb),所以我怀疑https://serverfault.com/questions/315085/nginx-proxy-pass-response-truncated是问题,但目前我认为它没有关系。

这种情况有什么问题?

这是我的nginx配置。

/etc/nginx/nginx.conf

user nginx;
worker_processes auto;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" '
                  '$request_time $upstream_response_time '
                  '"$http_x_app_os" "$http_x_app_version" "$http_x_kidsly_model"';

  access_log /var/log/nginx/access.log main;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  server_tokens off;

  set_real_ip_from ${ELB_SUBNET_CIDR_AZ_A};
  set_real_ip_from ${ELB_SUBNET_CIDR_AZ_C};
  real_ip_header X-Forwarded-For;

  client_max_body_size 50M;

  include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
  listen 80 default_server;
  server_name  _;

  include /etc/nginx/mime.types;

  keepalive_timeout 120;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_read_timeout 180;
    proxy_send_timeout 180;

    proxy_pass http://app:8080/;
  }

  location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
  }
}

0 个答案:

没有答案