Nginx报错解决
随着并发量上升,nginx开始出现502,即nginx已经发现不了存活的后端了
但是web程序没有任何错误,后端的数据库也很正常,查看nginx错误日志
tail -f /usr/local/nginx/log/error.log
但是web程序没有任何错误,后端的数据库也很正常,查看nginx错误日志
tail -f /usr/local/nginx/log/error.log
[error] 31365#0: *11971189 upstream timed out (110: Connection timed out) while reading response header from upstream host: "192.168.12.127"
修改proxy_read_timeout,proxy_send_timeout和proxy_buffer几个相关设置的值
在server标签添加
large_client_header_buffers 4 16k; client_max_body_size 30m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 64k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; fastcgi_connect_timeout 300; fastcgi_read_timeout 300; fastcgi_send_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 32k; fastcgi_busy_buffers_size 64k; fastcgi_temp_file_write_size 64k;
proxy_和fastcgi_两种配置,就是说如果你的nginx后面是proxy,就设置proxy相关的配置,如果是fastcgi就设置fastcgi相关的配置
more /usr/local/nginx/nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream eureka { server 192.168.12.104:8082; server 192.168.12.127:8080; keepalive 256; } server { listen 80; server_name localhost; large_client_header_buffers 4 16k; client_max_body_size 30m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 64k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; location / { proxy_redirect off; proxy_pass http://eureka; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; } } }