nginx tomcat7 错误:-“从上游读取响应标头时,recv() 失败(104:对等连接重置)”
Posted
技术标签:
【中文标题】nginx tomcat7 错误:-“从上游读取响应标头时,recv() 失败(104:对等连接重置)”【英文标题】:nginx tomcat7 ERROR : - “recv() failed (104: Connection reset by peer) while reading response header from upstream” 【发布时间】:2018-02-21 07:39:59 【问题描述】:我的 nginx 日志中有两种类型的错误。
Error-1 connect() 在连接时失败(110:连接超时) 到上游
Error-2 recv() 在读取时失败(104:连接被对等方重置) 来自上游的响应头
所以我的上游是 Tomcat7 和前端的 Nginx。
我不明白为什么会出现此错误。因为,当我在 8080 端口上点击 tomcat7 时,它的负载很重。但是当 Nginx(在端口 80 上运行)上的高负载命中时,代理对 tomcat7 的请求会因这 2 个错误而失败。我能得到的所有答案都是 php-FPM,但我没有使用它。我不知道如何解决。
已编辑:-
user www-data;
worker_processes auto;
worker_rlimit_nofile 10000;
pid /run/nginx.pid;
events
worker_connections 2000;
multi_accept on;
use epoll;
http
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
reset_timedout_connection on;
client_body_timeout 200s; # Use 5s for high-traffic sites
client_header_timeout 200s;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 9000;
keepalive_requests 100000;
types_hash_max_size 2048;
proxy_connect_timeout 16000s;
proxy_send_timeout 16000s;
proxy_read_timeout 16000s;
send_timeout 16000s;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# configuration file /etc/nginx/sites-enabled/default:
upstream _tomcat-stream-beta
server 127.0.0.1:8080;
keepalive 500000;
server
#recursive_error_pages on;
listen 80 default_server;
server_name 127.0.0.1;
#docshare Root WebSite
root /usr/share/nginx/www/;
# error_page 500 502 503 504 =200 /api/testing/errorHandle?headers=$http_attributes;
error_log /var/log/nginx/stream.error.log;
access_log /var/log/nginx/stream.access.log;
client_body_in_file_only on;
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;
large_client_header_buffers 8 64k;
location ~ /.well-known
allow all;
location @tomcat-stream-beta
proxy_pass http://_tomcat-stream-beta;
location ^~ /
proxy_pass http://_tomcat-stream-beta;
proxy_read_timeout 600000s;
proxy_connect_timeout 600000s;
proxy_send_timeout 600000s;
proxy_ignore_client_abort on;
【问题讨论】:
发布你的 nginx 配置。使用nginx -T
并将其输出作为配置发布
嗨,Tarun,编辑了我的问题,您可以查看我的“nginx -T”结果。
您的超时时间太长了。将它们降低到 90、120、150、180 之类的值,然后尝试您的配置。
【参考方案1】:
我最终使用了以下配置:-
我们必须加快内部代码,即代码执行时间。现在每个请求花费的时间不到 50 毫秒。
使用的 Nginx 配置是:-
user www-data;
worker_processes auto;
worker_rlimit_nofile 10000;
pid /run/nginx.pid;
events
worker_connections 2000;
multi_accept on;
use epoll;
http
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
reset_timedout_connection on;
client_body_timeout 200s; # Use 5s for high-traffic sites
client_header_timeout 200s;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 900;
keepalive_requests 10000;
types_hash_max_size 2048;
#proxy_buffering off;
proxy_connect_timeout 1600;
proxy_send_timeout 1600;
proxy_read_timeout 1600;
send_timeout 1600;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/stream.access.log;
error_log /var/log/nginx/stream.error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
【讨论】:
以上是关于nginx tomcat7 错误:-“从上游读取响应标头时,recv() 失败(104:对等连接重置)”的主要内容,如果未能解决你的问题,请参考以下文章
nginx tomcat7 错误:-“从上游读取响应标头时,recv() 失败(104:对等连接重置)”
Nginx + Tomcat7 + redis session一致性问题