我在 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 是一个简单的一行 phpinfo() 测试文件。 php-fpm 有什么问题吗?
答案1
好的,所以回答自己,我发现了错误 - 当我安装 php5-fpm 时,有一个旧的配置文件,其中包含错误的 unix 套接字路径。将 /etc/php/fpm/pool.d/www.conf 文件中的该行修复为:
/var/run/php5-fpm.sock
我能够看到 phpinfo 页面。