两天前,我在生产服务器(CentOS 6.8)上升级到 PHP7(PHP 7.0.14)。现在,我在 nginx (1.10.2-1) 日志中收到以下错误。
2017/01/20 08:20:04 [错误] 7654#7654: *153301 上游发送了意外的 FastCGI 记录:3 在从上游读取响应标头时,客户端:XXX.XXX.XXX.XXX,服务器:example.com,请求:“GET / HTTP/1.0”,上游:“fastcgi://unix:/var/run/php-fpm/example.fpm.sock:”,主机:“www.example.com”
- 我们有多个网站都在运行各自的 php-fpm 池,并且此错误同时出现在所有网站上。
- 在所有网站上出现此错误期间,浏览器都会显示“502 Bad Gateway”。
- 此错误会持续 1-2 分钟,之后一切都会自动恢复正常。
- 它在一天的不同时间发生了三次。
- PHP5没有问题。
- 我试图将 opcache 中的所有应用程序缓存文件夹列入黑名单
我们有另一台具有类似设置的服务器已升级到 PHP7,它没有此类问题。
我应该如何排除故障并找到解决此问题的方法?
更新 1
服务器详细信息
CPU:2x Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
RAM:256GB
操作系统:CentOS 版本 6.8
内核:2.6.32-504.8.1.el6.x86_64
PHP:使用 7.0.14 -3 来自 IUS 回购
Nginx:1.10.2-1
服务器用作 Web 服务器来运行多个运行流行的开源 PHP 应用程序的站点。我们使用 Nginx 和 php-fpm 作为后端。每个网站都有一个单独的 php-fpm 池和不同的套接字。PHP 应用程序已经与 php7 兼容,唯一的变化是升级到 PHP7。
更新 2
Nginx 主要配置
user apache;
worker_processes auto;
error_log /var/log/nginx/error.log alert;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 4024;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 256;
server_names_hash_max_size 1024;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
client_max_body_size 512M;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xmli font/ttf font/otf image/svg+xm;
gzip_buffers 16 24k;
gzip_disable msie6;
fastcgi_connect_timeout 120;
fastcgi_send_timeout 1200;
fastcgi_read_timeout 1200;
fastcgi_buffer_size 256k;
fastcgi_buffers 16 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
keepalive_requests 10000;
include /etc/nginx/conf.d/*.conf;
# Load all vhosts !
include /etc/nginx/sites-enabled/*.conf;
}
单个 nginx 站点模板
server {
server_name @@HOSTNAME@@ www.@@HOSTNAME@@;
root "@@PATH@@";
index index.php index.html index.htm;
add_header Cache-Control public;
client_max_body_size 512m;
access_log @@LOG_PATH@@/access.log;
error_log @@LOG_PATH@@/error.log;
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ $uri/index.php @rewrite /index.php$uri?$args;
}
location @rewrite {
rewrite ^ /index.php;
}
location ~ \.php$ {
send_timeout 1200;
proxy_read_timeout 1200;
proxy_connect_timeout 120;
fastcgi_read_timeout 1200;
fastcgi_pass unix:@@SOCKET@@;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}
location ~* \.(html|htm)$ {
expires 30m;
}
location ~* /\.(ht|git|svn|bak) {
deny all;
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
}
PHP FPM 池模板
[@@USER@@]
listen = /var/run/php-fpm/@@USER@@.fpm.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = @@USER@@
group = @@USER@@
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 300s
pm.max_requests = 5000
rlimit_files = 1024
request_terminate_timeout = 1200s
security.limit_extensions = .php
php_admin_value[session.save_path] = "@@HOME_DIR@@/_sessions"
php_admin_value[error_log] = "@@HOME_DIR@@/logs/www-error.log"
更新 3 出现问题时
请求 1
GET /moodle/ HTTP/1.0
User-Agent: Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)
Host: www.example.com
收到的标头
502 Bad Gateway
Server: nginx/1.10.2
Date: Wed, 25 Jan 2017 12:32:00 GMT
Content-Type: text/html
Content-Length: 173
Connection: close
收到的内容
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.2</center>
</body>
</html>