我正在使用 nginx + tomcat。
出现间歇性 nginx 502 错误。
error.log 内容如下。
2019/10/08 06:40:54 [error] 52996 # 0: * 25112952 recv () failed (104:
Connection reset by peer) while reading response header from upstream, client:
00.000.000.00, server: aaa.bbb. ccc, request: "POST / servlet / AAServlet HTTP /
1.1", upstream: "http://111.111.111.111:8888/servlet/AAServlet", host:
"aaa.bbb.ccc: 1234", referrer: "https: //qqq.www.eee/test.do "
nginx配置如下:
**nginx.conf**
worker_processes 2;
error_log logs / error.log notice;
events {
worker_connections 1024;
}
http {
proxy_http_version 1.1;
underscores_in_headers on;
server_names_hash_bucket_size 64;
include mime.types;
default_type application / octet-stream;
log_format lf '$ remote_addr, "$ time_local", "$ request_uri", $ status, $ request_time,
$ body_bytes_sent';
sendfile on;
keepalive_timeout 15;
error_page 400 401 403 402 404 405 = /error/50x.html;
include vhosts / test.conf;
}
**test.conf**
upstream test.ssl.web {
ip_hash;
server 111.111.111.111:8000 max_fails = 3 fail_timeout = 30s;
server 111.111.111.112:8000 max_fails = 3 fail_timeout = 30s;
}
server {
listen 443;
server_name aaa.bbb.com;
access_log logs / test.443.access.log lf;
proxy_buffering on;
proxy_read_timeout 80s;
proxy_buffer_size 1024k;
proxy_buffers 1024 1024k;
proxy_busy_buffers_size 1024k;
client_body_buffer_size 1024k;
server_tokens off;
ssl on;
ssl_certificate XXXXX;
ssl_certificate_key XXXXX;
ssl_session_timeout 5m;
ssl_protocols XXXXX;
ssl_ciphers XXXXX;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
limit_except GET POST {
deny all;
}
proxy_pass http://test.ssl.web/;
}
}
- 服务器不忙。
- 显示 nginx 502 错误(在错误日志中,104: Connection reset by peer)。
- 重新加载后正常运行。
- 我变了,但还是一样。
worker_connections 1024-> 2048
keepalive_timeout 15-> 80
max_fails = 3 fail_timeout = 30s-> 3, 10