nginx tomcat7 ERROR : - “recv() failed (104: Connection reset by peer) while reading response header from upstream”
nginx tomcat7 ERROR : - “recv() failed (104: Connection reset by peer) while reading response header from upstream”
我的 nginx 日志中出现两种类型的错误。
Error-1 connect() failed (110: Connection timed out) while connecting
to upstream
Error-2 recv() failed (104: Connection reset by peer) while reading
response header from upstream
所以我的上游是前端的Tomcat7和Nginx。
我不明白为什么会出现此错误。因为,当我在 8080 端口上点击 tomcat7 时,它会承受很重的负载。但是当在 Nginx(端口 80 上的运行)上以高负载命中时,代理对 tomcat7 的请求因这两个错误而失败。我能得到的所有答案都是 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;
}
}
我最终使用了以下配置:-
我们不得不加快我们的内部代码,即代码执行时间。现在每个请求花费的时间少于 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 日志中出现两种类型的错误。
Error-1 connect() failed (110: Connection timed out) while connecting to upstream
Error-2 recv() failed (104: Connection reset by peer) while reading response header from upstream
所以我的上游是前端的Tomcat7和Nginx。
我不明白为什么会出现此错误。因为,当我在 8080 端口上点击 tomcat7 时,它会承受很重的负载。但是当在 Nginx(端口 80 上的运行)上以高负载命中时,代理对 tomcat7 的请求因这两个错误而失败。我能得到的所有答案都是 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;
}
}
我最终使用了以下配置:-
我们不得不加快我们的内部代码,即代码执行时间。现在每个请求花费的时间少于 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/*;
}