php 对等方重置连接:mod_fcgid:从 FastCGI 服务器读取数据时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12153518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connection reset by peer: mod_fcgid: error reading data from FastCGI server
提问by James Wise
I am having issue on PHP where my app is trying to run a php backup file and suddenly getting HTTP Error 500 Code. I have checked the logs and this what it saying.
我在 PHP 上遇到问题,我的应用程序试图运行一个 php 备份文件并突然收到 HTTP 错误 500 代码。我检查了日志和它所说的内容。
[Tue Aug 28 14:17:28 2012] [warn] [client x.x.x.x] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://example.com/backup/backup.php
[Tue Aug 28 14:17:28 2012] [error] [client x.x.x.x] Premature end of script headers: backup.php, referer: http://example.com/backup/backup.php
[2012 年 8 月 28 日星期二 14:17:28] [警告] [客户端 xxxx] (104) 对等方重置连接:mod_fcgid:从 FastCGI 服务器读取数据时出错,引用:http: //example.com/backup/backup.php
[2012 年 8 月 28 日星期二 14:17:28] [错误] [客户端 xxxx] 脚本头过早结束:backup.php,referer:http: //example.com/backup/backup.php
Anyone knows how to fix this? I'm really stuck in here and can't find solution in internet.
有谁知道如何解决这个问题?我真的被困在这里,无法在互联网上找到解决方案。
Hope anyone could share their knowledge.
希望任何人都可以分享他们的知识。
Thanks. James
谢谢。詹姆士
回答by James Wise
I managed to solved this by adding FcgidBusyTimeout . Just in case if anyone have similar issue with me.
我设法通过添加FcgidBusyTimeout解决了这个问题。以防万一,如果有人和我有类似的问题。
Here is my settings on my apache.conf:
这是我在 apache.conf 上的设置:
<VirtualHost *:80>
.......
<IfModule mod_fcgid.c>
FcgidBusyTimeout 3600
</IfModule>
</VirtualHost>
回答by Oliver Hader
I had very similar errors in the Apache2 log files:
我在 Apache2 日志文件中有非常相似的错误:
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
Premature end of script headers: phpinfo.php
After checking the wrapper scripts and Apache2 settings, I realized that /var/www/ did not have accordant permissions. Thus the FCGId Wrapper scripts could not be read at all.
检查包装脚本和 Apache2 设置后,我意识到 /var/www/ 没有一致的权限。因此,根本无法读取 FCGId 包装器脚本。
ls -la /var/www
drwxrws--- 5 www-data www-data 4096 Oct 7 11:17 .
For my scenario chmod -o+rx /var/wwwwas required of course, since the used SuExec users are not member of www-datauser group - and they should not be member for security reasons of course.
对于我的场景chmod -o+rx /var/www,当然是必需的,因为使用的 SuExec 用户不是www-data用户组的成员- 当然出于安全原因,他们不应该是成员。
回答by reiner23fx
if you want to install a PHP version < 5.3.0, you must replace
如果要安装 PHP 版本 < 5.3.0,则必须替换
--enable-cgi
with:
和:
--enable-fastcgi
in your ./configurestatement, excerpt from the php.net doc:
在您的./configure声明中,摘自 php.net 文档:
--enable-fastcgi
If this is enabled, the CGI module will be built with support for FastCGI also. Available since PHP 4.3.0
如果启用此功能,CGI 模块也将在支持 FastCGI 的情况下构建。自 PHP 4.3.0 起可用
As of PHP 5.3.0 this argument no longer exists and is enabled by --enable-cgi instead. After the compilation the ./php-cgi -vshould look like this:
从 PHP 5.3.0 开始,此参数不再存在,而是由 --enable-cgi 启用。编译后./php-cgi -v应该是这样的:
PHP 5.2.17 (cgi-fcgi) (built: Jul 9 2013 18:28:12)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
NOTICE THE (cgi-fcgi)
注意 (cgi-fcgi)
回答by sEver
I had this issue and realized that the file cgi-bin/php-fcgi had no execution rights.
我遇到了这个问题并意识到文件 cgi-bin/php-fcgi 没有执行权限。
It had 644 mode while is should have 755 mode.
它有 644 模式,而应该有 755 模式。
Setting the correct mode was impossible (probably because the file was opened or sth), so I copied that file from another domain directory where it had proper rights already set and that fixed everything.
设置正确的模式是不可能的(可能是因为文件被打开或某事),所以我从另一个域目录复制了该文件,该目录已经设置了适当的权限并修复了所有问题。
回答by user5626466
I had the same problem with a different and simple solution.
我用不同的简单解决方案遇到了同样的问题。
Problem
问题
I installed PHP 5.6 following the accepted answer to this question on Ask Ubuntu. After using Virtualmin to switch a particular virtual server from PHP 5.5 to PHP 5.6, I received a 500 Internal Server Error and had the same entries in the apache error log:
我在 Ask Ubuntu 上接受了这个问题的答案后安装了 PHP 5.6 。在使用 Virtualmin 将特定的虚拟服务器从 PHP 5.5 切换到 PHP 5.6 后,我收到了 500 Internal Server Error 并且在 apache 错误日志中有相同的条目:
[Tue Jul 03 16:15:22.131051 2018] [fcgid:warn] [pid 24262] (104)Connection reset by peer: [client 10.20.30.40:23700] mod_fcgid: error reading data from FastCGI server
[Tue Jul 03 16:15:22.131101 2018] [core:error] [pid 24262] [client 10.20.30.40:23700] End of script output before headers: index.php
Cause
原因
Simple: I didn't install the php5.6-cgipacket.
很简单:我没有安装php5.6-cgi包。
Fix
使固定
Installing the packet and reloading apache solved the problem:
安装数据包并重新加载apache解决了问题:
sudo apt-get install php5.6-cgiif you are using PHP 5.6sudo apt-get install php5-cgiif you are using a different PHP 5 versionsudo apt-get install php7.0-cgiif you are using PHP 7
sudo apt-get install php5.6-cgi如果您使用的是PHP 5.6sudo apt-get install php5-cgi如果您使用的是不同的 PHP 5 版本sudo apt-get install php7.0-cgi如果您使用的是PHP 7
Then use service apache2 reloadto apply the configuration.
然后使用service apache2 reload来应用配置。
回答by Lance
I came across this one while debugging a virtualmin/apache related error.
我在调试与 virtualmin/apache 相关的错误时遇到了这个问题。
In my case, I am running virtualmin and had in my virtual machine's php.ini safe_mode=On.
就我而言,我正在运行 virtualmin 并且在我的虚拟机的 php.ini safe_mode=On 中有。
In my Virtual Machine's error log, I was getting the fcgi Connection reset by peer: mod_fcgid: error reading data from FastCGI server
在我的虚拟机的错误日志中,我得到了对等方重置的 fcgi 连接: mod_fcgid: error reading data from FastCGI server
In my main apache error log I was getting: PHP Fatal error: Directive 'safe_mode' is no longer available in PHP in Unknown on line 0
在我的主要 apache 错误日志中,我得到了:PHP 致命错误:指令 'safe_mode' 在第 0 行的未知 PHP 中不再可用
In my case, I simply set safe_mode = Off in my php.ini and restarted apache.
就我而言,我只需在 php.ini 中设置 safe_mode = Off 并重新启动 apache。
stackoverflow.com/questions/18683177/where-to-start-with-deprecated-directive-safe-mode-on-line-0-in-apache-error
stackoverflow.com/questions/18683177/where-to-start-with-deprecated-directive-safe-mode-on-line-0-in-apache-error
回答by joruf81
I had the same problem with long-running scripts with the error messages "Premature end of script headers: index.php" and "Connection reset by peer: mod_fcgid: error reading data from FastCGI server" in error_log. After hours of testing this helps for me (CentOS 6, PHP-FPM 7, Plesk 12.5.30):
我在长时间运行的脚本中遇到了同样的问题,在 error_log 中出现错误消息“脚本头过早结束:index.php”和“对等方重置连接:mod_fcgid:从 FastCGI 服务器读取数据时出错”。经过数小时的测试,这对我有帮助(CentOS 6、PHP-FPM 7、Plesk 12.5.30):
edit the config file:
编辑配置文件:
/etc/httpd/conf.d/fcgid.conf
/etc/httpd/conf.d/fcgid.conf
Set a higher running time. In my case 600 seconds
设置更高的运行时间。在我的情况下 600 秒
create the new entry:
创建新条目:
FcgidBusyTimeout 600
FcgidBusy 超时 600
adapt following entries:
调整以下条目:
FcgidIOTimeout 600
FcgidConnectTimeout 600
FcgidIO 超时 600
FcgidConnectTimeout 600
restart httpd:
重启httpd:
service httpd restart
服务 httpd 重启
回答by Jivko Todorov
In CentOS releases suexec is compiled to run only in /var/www. If you try to set a DocumentRoot somewhere else you have to recompile it - the error in apache log are: (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server Premature end of script headers: php5.fcgi
在 CentOS 发行版中,suexec 被编译为仅在 /var/www 中运行。如果您尝试在其他地方设置 DocumentRoot,则必须重新编译它 - apache 日志中的错误是:(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server Premature end of script headers: php5.fcgi
回答by owenmck
The famous Moodle "replace.php" script can generate this situation too. For me it was taking ages to run and then failed with a 500 message in the browser and also with the above error message in my apache error log file.
著名的 Moodle“replace.php”脚本也可以产生这种情况。对我来说,它需要很长时间才能运行,然后在浏览器中出现 500 消息而失败,并且在我的 apache 错误日志文件中也出现了上述错误消息。
I followed up on @james-wise answer:
FcgidBusyis readably described in the Apache documentation. I tried this: doubled the amount of time which apache would give my script to run, by inserting the following line in /etc/apache2/mods-available/fcgid.conf
我跟进了@james-wise 的回答:
FcgidBusy在Apache 文档中进行了易读的描述。我试过这个:通过在 /etc/apache2/mods-available/fcgid.conf 中插入以下行,将 apache 给我的脚本运行的时间加倍
FcgidBusyTimeout 600
Then I restarted Apache and tried to run my replace.php script again.
然后我重新启动 Apache 并尝试再次运行我的 replace.php 脚本。
Fortunately this time the script instance ran to completion, so for my purposes this served as a solution.
幸运的是,这次脚本实例运行完成,因此就我而言,这是一个解决方案。
回答by hakre
Not in this questions askers casebut often:
不是在这个提问者的情况下,而是经常:
What does the "premature end of script headers"error mean?
什么是“脚本头过早结束”错误是什么意思?
That error means that the FCGI call was exited unexpectedly.
该错误意味着 FCGI 调用意外退出。
In some cases it means that the script "backup.php" did crash.
在某些情况下,这意味着脚本“backup.php”确实崩溃了。
How to fix this?
如何解决这个问题?
If the crash of a script was the cause, fix the script so that it does not crash. Then this error is fixed, too. To find out ifand whya script crashes, you need to debug it. For example you can check the PHP error log. Errors logged to STDERR normally go into the error handler of the FCGI.
如果脚本崩溃是原因,请修复脚本以使其不会崩溃。然后这个错误也被修复了。要了解脚本是否以及为什么会崩溃,您需要对其进行调试。例如,您可以检查 PHP 错误日志。记录到 STDERR 的错误通常会进入 FCGI 的错误处理程序。

