Apache代理_fcgi - 分派请求时出错

31

我在谷歌上使用云托管,说实话体验很糟糕,但我正在努力适应它。我在虚拟机上安装了LAMP堆栈,并将我的网站放在htdocs中。当我尝试访问我的网站时,它会显示“请求超时”,但有时它能正常工作5分钟左右。

当我查看Apache错误日志时,它给出了以下提示:

075: Error dispatching request to : (polling)
[Tue Oct 27 18:12:55.185819 2015] [proxy_fcgi:error] [pid 4995:tid 140183521683200] (70007)The timeout specified has expired: [client 162.158.255.169:34198] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:12:55.487458 2015] [core:notice] [pid 2953:tid 140183785137920] AH00052: child pid 4995 exit signal Segmentation fault (11)
[Tue Oct 27 18:12:55.787973 2015] [proxy_fcgi:error] [pid 5063:tid 140183530075904] (70007)The timeout specified has expired: [client 199.27.133.137:13151] AH01075: Error dispatching request to : (polling), referer: http://whichtube.com/watch/g9-4dCeFQng/allama-nasir-abbas-jawab-ali-as-nae-talwar-kayou-na-uthai.html
[Tue Oct 27 18:12:57.542883 2015] [proxy_fcgi:error] [pid 5329:tid 140183521683200] (70007)The timeout specified has expired: [client 173.245.56.198:51348] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:12:57.976752 2015] [proxy_fcgi:error] [pid 5063:tid 140183479719680] (70007)The timeout specified has expired: [client 173.245.56.198:63779] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:12:58.993666 2015] [proxy_fcgi:error] [pid 5194:tid 140183496505088] (70007)The timeout specified has expired: [client 162.158.255.141:16226] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:12:59.196701 2015] [proxy_fcgi:error] [pid 5329:tid 140183513290496] (70007)The timeout specified has expired: [client 173.245.56.198:32819] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:01.462039 2015] [proxy_fcgi:error] [pid 5329:tid 140183504897792] (70007)The timeout specified has expired: [client 199.27.128.166:48057] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:07.518999 2015] [proxy_fcgi:error] [pid 5063:tid 140183471326976] (70007)The timeout specified has expired: [client 173.245.56.198:13694] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:16.804990 2015] [proxy_fcgi:error] [pid 5261:tid 140183513290496] (70007)The timeout specified has expired: [client 199.27.128.134:28694] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:33.055860 2015] [proxy_fcgi:error] [pid 5328:tid 140183236331264] (70007)The timeout specified has expired: [client 39.41.139.220:52154] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:57.391361 2015] [proxy_fcgi:error] [pid 5063:tid 140183521683200] (70007)The timeout specified has expired: [client 39.41.139.220:52029] AH01075: Error dispatching request to : (polling)
[Tue Oct 27 18:13:57.552542 2015] [core:notice] [pid 2953:tid 140183785137920] AH00052: child pid 5063 exit signal Segmentation fault (11)

我的网站用的是PHP,除了目录权限之外,我没有改变任何其他东西,我是否漏了什么?

7个回答

19

我遇到了同样的问题,结果发现Apache有一个处理超时的模块,名为mod_reqtimeout

默认值(在默认的http.conf中看不到)是:

RequestReadTimeout handshake=0 header=20-40,MinRate=500 body=20,MinRate=500

在我的情况下,我通过普通HTML表单提交上传了一个文件,所以该文件在技术上是标头的一部分,而默认配置规定标头将在20至40秒后超时。这个20-40的设置非常棒,因为它会在20秒超时,但如果每秒发送500字节,则会添加额外的等待时间直到达到40秒,然后无论如何都会超时。

我在我的网站上上传更大的文件,因此我将以下行添加到我的httpd.conf文件中:

RequestReadTimeout handshake=0 header=20-600,MinRate=500 body=20,MinRate=500
只要我的用户以至少500字节/秒的速度发送数据,请求将不会超时,直到达到最大值600秒为止(最好阅读文档,不要引用我关于吞吐率的话)。这实际上是一个非常酷的Apache模块,但并不像其他与PHP-FPM相关的“已过期的超时指定”问题那样广为人知,因为人们建议更改其他Apache超时设置,但是此问题在任何需要默认提交超过40秒的帖子时都会出现。

proxy_fcgi 的 AH01075 错误消息表示被代理到 php-fpm 的请求已超时,可能是因为超过了 ProxyTimeout。你是说当 RequestReadTimeout 被触发时,你看到了相同的错误吗?我问这个问题是因为如果涉及到 RequestReadTimeout,我会预期看到类似于“请求正文读取超时”的内容。 - molecularbear
@molecularbear 我得到的确切错误是:[Fri May 10 13:19:41.073170 2019] [proxy_fcgi:error] [pid 26964:tid 140276668856064] (70007)The timeout specified has expired: [client 201.17.156.113:2022] AH01075: Error dispatching request to : (reading input brigade), referer: https://siste.. 这个超时是因为用户上传到我的 PHP 脚本的文件(实际上是在 POST 标头中发送的)花费的时间比默认值长,所以它超时了。 - Roberto Ibarra Rabadán
请注意,handshake变量在Apache版本2.4.39之前不可用 - Christophorus Reyhan

11

看起来你的PHP代码正在超过配置的超时时间才能完成。当Apache使用fcgi加载PHP页面时,它将请求发送到PHP-FPM服务进行处理。如果PHP-FPM响应时间太长,则会出现此类型的超时。可能的原因是:你的PHP代码可能被卡在循环中,或者正在等待来自数据库的响应,这需要特别长的时间。

为了进行故障排除,我建议使用php的CLI版本来查看脚本是否在合理的时间内完成($ time php /path/to/file.php)。PHP-FPM日志中可能会有其他信息(默认:/var/log/php-fpm.log)。


8

对于我来说,重启php-fpm就解决了问题。在像@varlogtim建议的那样查看日志后,日志显示最近12小时没有任何活动...


3

我也遇到过这个问题。你可能需要查找你代码中的硬编码部分和与另一个不可用服务器的连接(例如本地IP在线上无法访问)。

对于我的情况,我在我的服务器上检查了php-fpm.log,发现我的应用程序尝试连接到一个旧服务器(错误的IP),并且面临超时问题。


2

我曾经遇到过这个问题。我通过增加超时时间来解决了这个问题。我的操作系统是AlmaLinux 8.5。请在您的httpd.confvirtualhost配置文件中添加以下两行。

Timeout 600

ProxyTimeout 600


1
我遇到了同样的问题,在我的情况下,这个解决方案有效:
  • 增加/etc/php-fpm.d/www.conf文件中的request_terminate_timeout值。
注意:此选项覆盖php的max_execution_timeini选项,如果将其设置为低值可能会引起很多麻烦,因为它将覆盖其他选项并在超时后强制终止请求。(如果您想知道要设置哪个值,则应根据您的需求设置最大脚本处理时间,但通常600秒(10分钟)或10m(10分钟)已经足够。)

-3

我在Centos 7上遇到了同样的问题:SELINUX的问题。 你可以暂时禁用SELINUX来进行检查: sudo setenforce 0


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接