使用Nginx 1.6.2和PHP 5.6.4在Ubuntu 14.04上使用502 Bad Gateway

时间:2015-10-20 08:40:13

标签: php ubuntu nginx

我在超过5分钟的脚本上获得502 Bad Gateway响应。

服务器使用Nginx 1.6.2和PHP 5.6.4在Ubuntu 14.04上运行

我创建了一个测试函数,但失败了:

    public function test(){
        sleep(600);
    }

我尝试更改fastcgi参数,没有任何变化。

配置:

server {
    listen 80;
    server_name www.xxxx.xx;
    root /home/forge/xxxx.xx/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/xxxx.xx-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_param PHP_VALUE "newrelic.appname=xxxx.xx";
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }

}

nginx.conf http块(部分I' v已更改):

http {
    fastcgi_buffers 32 32k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_read_timeout 3600;
    # EDIT: Added and tried these:
    client_header_timeout 3600;
    client_body_timeout 3600;
    proxy_read_timeout 3600;
    proxy_connect_timeout 3600;

}

的php.ini:

max_execution_time = 3600

记录错误:

2015/10/20 10:01:12 [error] 5132#0: *297705 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 195.215.168.170, server: xxxx.xx, request: "GET /cron/test HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xxxx.xx"

花了无数个小时寻找解决方案,但我试过的每一个解决方案都没有任何效果。所以任何帮助都是张开双臂欢迎的!

1 个答案:

答案 0 :(得分:1)

通过增加$page = $this->Pages->findBySlug(1) ->select('id'); $id = $page->id; 中的request_terminate_timeout值,我能够摆脱502 Bad Gateway。

感谢@JuniusRendel的解决方案。