504网关超时nginx + php5-fpm

时间:2014-06-28 07:35:15

标签: nginx php http-status-code-504

我意识到这可能是一个重复的问题,但没有其他人帮助我(在搜索解决方案4天之后)。

我使用nginx + php5-fpm作为Web应用程序。它在Apache中完美运行,所以我知道它有一些配置问题。

我的网页加载时应该像1-5次一样,然后他们只是不加载,然后我每次都会得到504网关超时。

在我的慢速日志中,我可以看到所有PHP操作都是成功的,并且还执行了最后一个函数。我不明白,这是因为php5-fpm?

慢速日志:

[28-Jun-2014 12:45:33]  [pool www] pid 21245
script_filename = /home/XXX/public_html/feed.php
[0x00000000014a48f8] usleep() /home/XXX/cache.class.php:864
[0x00000000014a46c8] addLock() /home/XXX/cache.class.php:902
[0x00000000014a44e0] increment() /home/XXX/channel.class.php:124
[0x00000000014a4200] incrementWorkstamp() /home/XXX/channel.class.php:102
[0x00000000014a3f20] getWorkstamp() /home/XXX/channel.class.php:103
[0x00000000014a2908] getWorkstamp() /home/XXX/public_html/feed.php:162

现在我在慢速日志中获得转储失败:

[28-Jun-2014 12:52:40]  [pool www] pid 29136
script_filename = /home/XXX/public_html/index.php
[0x00007fd7388d7620] session_start() /home/XXX/headers.php:2
[0x00007fd7388d7068] +++ dump failed

Web应用程序的nginx配置:

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /home/XXX/public_html;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php?$query_string;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }

    error_page 500 /errors/6.php;
    error_page 404 /errors/4.php;
    error_page 403 /errors/2.php;

    if (!-e $request_filename){
        rewrite ^/user\/([^/]+)\/?([a-zA-Z]*)? /profile.php?username=$1&tab=$2 last;
    }
    if (!-e $request_filename){
        rewrite ^/messages\/([^/]+)\/? /messages.php?chat=$1 last;
    }
    if (!-e $request_filename){
        rewrite ^/interests\/([^/]+)\/? /interests.php?interest=$1 last;
    }

    if (!-e $request_filename){
        rewrite ^/(.*?)/?$ /$1.php last;
    }
}

更新:session_start()可能是罪魁祸首吗?我认为它一开始就挂起了吗?

1 个答案:

答案 0 :(得分:0)

解决。显然,这是函数getWorkstamp()导致问题,无限循环。