502エラーNginxとphp5-fpm

502エラーNginxとphp5-fpm

php5-fpmとnginxで奇妙な502問題が発生しました。 Nginx仮想ホストの設定:

server {
    server_name _;
    listen 7777 default_server;
#        root /var/www/html;
    root /var/www/test_app;
#        index index.php;
    index index.php index.html index.htm;

            location / {
              try_files $uri /index.html;
            }

#   location / {
#                try_files $uri $uri/ =404;
#        }

    location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort on;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_max_temp_file_size 0;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    }

}

php5-fpmにはデフォルト設定があります。私はいくつかのデバッグラインを追加しました:

[www]
access.log = /var/log/php5-fpm/access.log
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = true

/var/www/ ディレクトリは www-data に属し、660 個のファイルがあります。ソケットファイル/var/run/php5-fpm.sockが存在します。 /var/log/php5-fpm/error.log には興味深い内容はありません。

[01-Jan-2018 20:29:44] NOTICE: fpm is running, pid 14336
[01-Jan-2018 20:29:44] NOTICE: ready to handle connections
[01-Jan-2018 20:29:44] NOTICE: systemd monitor interval set to 10000ms
[01-Jan-2018 20:50:40] NOTICE: Terminating ...
[01-Jan-2018 20:50:40] NOTICE: exiting, bye-bye!
[01-Jan-2018 20:50:41] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf te$

[01-Jan-2018 20:50:41] NOTICE: fpm is running, pid 14463
[01-Jan-2018 20:50:41] NOTICE: ready to handle connections
[01-Jan-2018 20:50:41] NOTICE: systemd monitor interval set to 10000ms

ただし、nginxログには重複したエラーがたくさんあります。

sudo grep error /var/log/nginx/error.log
2018/01/01 20:50:43 [error] 14453#0: *4 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 44.33.22.11, server: _, request: "GET /favicon.ico HTTP/1.1", host: "11.22.33.44:7777", referrer: "http://11.22.33.44:7777/index.html"

/var/log/php5-fpm/access.log が空です。 index.phpは単純な1行のphpinfo()テストファイルです。 php-fpmに問題がありますか?

ベストアンサー1

さて、自分で答えるとバグが見つかりました。 php5-fpmをインストールしたとき、無効なUnixソケットパスを含む古い設定ファイルがありました。 /etc/php/fpm/pool.d/www.conf ファイルで、この行を次のように変更します。

/var/run/php5-fpm.sock

phpinfoページを見ることができます。

おすすめ記事