At the same time, the following error appears in the nginx error log:
Code: Select all
output on closed stream while sending to client
The issue appears to be related to PHP scripts generating a large number of warnings, notices or other error messages that are being transferred to Apache through the FastCGI protocol.
Under certain circumstances, this may cause premature termination of the response stream. Apache may send a response with Content-Length: 0, followed by the actual HTML content, causing nginx to attempt to send data to an already closed HTTP/2 stream.
Solution:
Edit the PHP-FPM pool configuration file for the affected domain:
Code: Select all
/etc/php/X.X/fpm/pool.d/YOURDOMAIN.COM.conf
Code: Select all
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-site-errors/YOURDOMAIN.COM.log
Code: Select all
mkdir -p /var/log/php-site-errors
touch /var/log/php-site-errors/YOURDOMAIN.COM.log
chown USERNAME:USERNAME /var/log/php-site-errors/YOURDOMAIN.COM.log
chmod 600 /var/log/php-site-errors/YOURDOMAIN.COM.log
Make sure that the PHP-FPM pool user has write access to the log file and that the path is permitted by open_basedir, if applicable.
Restart PHP-FPM to apply the new settings:
Code: Select all
systemctl restart phpX.X-fpm
Unlike disabling PHP error reporting entirely, this solution allows you to keep PHP error logging enabled and continue debugging your PHP application.
Important: The dedicated PHP error log may grow very quickly if the application generates a large number of warnings. Make sure to configure log rotation and investigate the underlying PHP warnings.
This solution has been successfully tested on a production server where hundreds of these nginx errors had previously occurred. After applying the workaround, no further occurrences were observed during 13 hours of monitoring.
Possibly related PHP bugs:
https://bugs.php.net/bug.php?id=72185
https://bugs.php.net/bug.php?id=81589
Related myVesta Knowledge Base article:
Error: Zlib error -2 deflating data ((null))
