nginx tomcat7错误: - 从上游读取响应头时“recv()失败(104:对等连接重置)”

时间:2017-09-12 18:28:05

标签: java spring nginx tomcat7

我的nginx日志中出现了两种类型的错误。

  连接时

错误-1连接()失败(110:连接超时)   到上游

     

错误-2 recv()在读取时失败(104:由对等方重置连接)   来自上游的响应头

所以我的上游是前端的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;
	}
}

1 个答案:

答案 0 :(得分:0)

我最终使用以下配置: -

  1. 我们必须加快内部代码,即代码执行时间。现在每个请求的时间不到50毫秒。

  2. 使用的Nginx配置是: -

  3. 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/*;
    }