phpcgi超时nginx响应502 错误处理

2017/05/20 nginx

phpcgi超时nginx响应502 错误处理

现象

某功能请求国外接口,由于请求时间常导致nginx等不到cgi响应的结果提前响应返回502

旧配置

server
{
    listen       8080;
    server_name  xxxxx.com;
    index index.html index.htm index.php;
    root  /home/wwwroot/xxxxx.com/webroot;
    keepalive_timeout 75 20;

    location / {
        root  /home/wwwroot/xxxxx.com/webroot;
        index index.php index.html index.htm;
    }

    location ~* .*\.php($|/) {
        allow 172.17.0.0/16;
        allow 10.0.0.0/8;
        deny all;
        include fastcgi_params;
        fastcgi_pass  127.0.0.1:10080;
        #fastcgi_pass unix:/usr/local/php/etc/php-cgi.socket;
        fastcgi_index index.php;
        fastcgi_connect_timeout 600;
        fastcgi_send_timeout 600;
        fastcgi_read_timeout 600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME  /home/wwwroot/xxxxx.com/webroot$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    ....
}

新配置

改动: keepalive_timeout 75 20; => keepalive_timeout 300;

server
{
    listen       8080;
    server_name  xxxxx.com;
    index index.html index.htm index.php;
    root  /home/wwwroot/xxxxx.com/webroot;
    keepalive_timeout 300;

    location / {
        root  /home/wwwroot/xxxxx.com/webroot;
        index index.php index.html index.htm;
    }

    location ~* .*\.php($|/) {
        allow 172.17.0.0/16;
        allow 10.0.0.0/8;
        deny all;
        include fastcgi_params;
        fastcgi_pass  127.0.0.1:10080;
        #fastcgi_pass unix:/usr/local/php/etc/php-cgi.socket;
        fastcgi_index index.php;
        fastcgi_connect_timeout 600;
        fastcgi_send_timeout 600;
        fastcgi_read_timeout 600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME  /home/wwwroot/xxxxx.com/webroot$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    ....
}

Search

    Table of Contents