压测发时返回502,观察nginx错误日志:
2018/12/28 17:59:54 [error] 505#0: *372671 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.0.1.67, server: cs.bs-advertising.arhieason.com, request: "GET /api/advertising?day_timestamp= HTTP/1.1", upstream: "http://10.0.1.63:8091/api/advertising?day_timestamp=", host: "10.0.1.63:82"
解决思路:
1.优化系统的IO:如tcp复用,打开文件数
2.nginx相关参数的优化
a)tcp
tcp_nopush on;
tcp_nodelay on;
b)http 1.1的 keepalive
keepalive_timeout 300;
c)proxy buffer :代理缓冲区
proxy_buffer_size 64k;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
types_hash_max_size 2048;
d)在相应的location中设置代理的timeout
proxy_connect_timeout 60;
最长不能超过75秒
如:
location ^~ /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-For