Nginx报错解决

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx报错解决相关的知识,希望对你有一定的参考价值。

随着并发量上升,nginx开始出现502,即nginx已经发现不了存活的后端了
但是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;
    }
    }
}

以上是关于Nginx报错解决的主要内容,如果未能解决你的问题,请参考以下文章

svn报错cleanup failed–previous operation has not finished; run cleanup if it was interrupted的解决办法(代码片段

Vue报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解决方法(代码片段

错误记录Flutter 混合开发获取 BinaryMessenger 报错 ( FlutterActivityAndFragmentDelegate.getFlutterEngine() )(代码片段

已解决在react+ts中 atnd 用 upload 组件报错Failed to execute ‘readAsArrayBuffer,param 1 is notof type Blob(代码片段

已解决在react+ts中 atnd 用 upload 组件报错Failed to execute ‘readAsArrayBuffer,param 1 is notof type Blob(代码片段

我的C语言学习进阶之旅解决 Visual Studio 2019 报错:错误 C4996 ‘fscanf‘: This function or variable may be unsafe.(代码片段