Nginx的 – PHP7意外的FastCGIlogging,同时从上游读取响应头

我在两天前在生产服务器(CentOS 6.8)上升级到PHP7(PHP 7.0.14)。 现在,我在nginx(1.10.2-1)日志中出现错误。

2017/01/20 08:20:04 [error] 7654#7654:上游发送* 153301意外FastCGIlogging:3从上游读取响应头时,客户端:XXX.XXX.XXX.XXX,服务器:example.com,请求:“GET / HTTP / 1.0”,上游:“fastcgi:// unix:/var/run/php-fpm/example.fpm.sock:”,主机:“www.example.com”

  1. 我们有多个网站都运行各自的php-fpm池,这个错误同时出现在所有网站上。
  2. 浏览器在所有网站上显示“502 Bad Gateway”错误。
  3. 这个错误来了1-2分钟,然后一切自动恢复正常。
  4. 在不同的时间,一天发生三次。
  5. PHP5没有问题。
  6. 我试图将opcache中的所有应用程序caching文件夹列入黑名单

我们有另一台服务器的设置已经升级到PHP7,它没有这样的问题。

我应该如何解决问题并find解决scheme?

更新1服务器详细信息
CPU:2个Intel(R)Xeon(R)CPU E5-2620 0 @ 2.00GHz
内存:256GB
操作系统:CentOS版本6.8
Kernal:2.6.32-504.8.1.el6.x86_64
PHP:使用IUS回购7.0.14-3
Nginx:1.10.2-1

服务器用作Web服务器来运行运行stream行的开源PHP应用程序的多个站点。 我们使用Nginx和php-fpm作为后端。 每个网站都有一个spe-php-fpm池和不同的套接字。 PHP应用程序已经与php7兼容,唯一的变化就是升级到PHP7。

更新2

Nginx的主要configuration

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> 

好的,所有的php-fpm池同时死了几分钟,唯一改变了php 5.6 => php 7. php7改变了什么? 什么是全球所有php-fpm池? opcache。 你会友善地提供你的php.ini吗? 如果没有,请检查您的opcacheconfiguration,并validation至less这些参数:

 zend_extension=opcache.so; opcache.enable=1; # on or off on your config ? opcache.memory_consumption=64; # Too small for you ? opcache.max_accelerated_files=2000; # maybe to small for you ? opcache.force_restart_timeout="180"; # Oh!!! This is the time of your outage!! 

将force_restart_timeout从180更改为120,将opcache.log_verbosity_level更改为> = 3,然后查看是否比平常短。然后,我build议您检查opcache运行时configuration,并为您的站点正确调整它。

看来这是PHP中的一个bug,它已经在2017年2月16日发布的7.0.16版本中修复了。

修正了bug# 67583 (max_children限制上的double fastcgi_end_request)。

检查nginx站点configuration中的fastcgi_pass服务器块。

要更新所有站点configuration运行的fastcgi_pass:

sed“s / php5 / php / php7.0 / g”* .conf -i

服务nginx && php7.0-fpm