记录一次nginx配置修改,修复偶发502 504错误的问题

1.优化配置一,502 504减少

下面是根据网上给的意见进行修改的配置,大部分描述是关于fastcgi的设置,此项设置会让502和504减少,但是偶尔还是会有

#user  nobody;
#worker_processes  根据CPU个数进行设置
worker_processes  8;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

worker_rlimit_nofile 65535;


events {
    worker_connections  655350;
     multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 2k;
    large_client_header_buffers 4 4k;

    open_file_cache max=204800 inactive=20s;
    open_file_cache_min_uses 1;
    open_file_cache_valid 30s;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    #tcp_nopush     on;

    keepalive_timeout  65;


    client_max_body_size  500m;

    proxy_connect_timeout   300;
    proxy_send_timeout      300;
    proxy_read_timeout      300;
    proxy_buffer_size       16k;
    proxy_buffers           4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;


#添加fastcgi设置后,502 504不再出现
    fastcgi_connect_timeout 300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;


    upstream  myserver{
        server 192.168.0.111:80;
    }

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        location /{

            proxy_pass http://myserver/;
        }
    }
}

2.优化配置二,502及504消失

这次试用stream模块进行代理

主要配置如下


#user  nobody;
worker_processes  8;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

worker_rlimit_nofile 65535;
events {
    worker_connections  655350;
	 multi_accept on;
}

stream {
    #将80端口转发到198.168.0.111:80
    server {
        listen 80;
        proxy_connect_timeout 5m;
        proxy_timeout 1440m;
        proxy_pass 198.168.0.111:80;
    }
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
	



    server {
        listen       90;
        server_name  localhost;



		location /{
		    root   html;
			index  index.html index.htm;
		}
    }
}

才用上述配置后,目前没有再发下502和504出现

你可能感兴趣的:(nginx,nginx)