Apache代理_fcgi - 已过期指定的超时时间 - 调度请求时出错

13

我有一个用PHP编写的应用程序,它返回以下内容:

[Thu Oct 05 22:10:59.351244 2017] [proxy_fcgi:error] [pid 3733:tid 139869435164416] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:46777] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:16:27.701213 2017] [proxy_fcgi:error] [pid 3732:tid 139869359630080] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:46988] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:21:52.971235 2017] [proxy_fcgi:error] [pid 3733:tid 139869426771712] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47055] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:25:23.561216 2017] [proxy_fcgi:error] [pid 3732:tid 139869351237376] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47115] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:30:47.591237 2017] [proxy_fcgi:error] [pid 3733:tid 139869418379008] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47321] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:39:10.211214 2017] [proxy_fcgi:error] [pid 3733:tid 139869443557120] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47407] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:39:38.591259 2017] [proxy_fcgi:error] [pid 3733:tid 139869376415488] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47412] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:45:13.951238 2017] [proxy_fcgi:error] [pid 3733:tid 139869582505728] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47615] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:50:36.491214 2017] [proxy_fcgi:error] [pid 3732:tid 139869460342528] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47668] AH01075: Error dispatching request to : (polling)
[Thu Oct 05 22:54:57.661219 2017] [proxy_fcgi:error] [pid 3733:tid 139869326059264] (70007)The timeout specified has expired: [client IPADDRESS HIDDEN:47726] AH01075: Error dispatching request to : (polling)

我认为上述信息在某种程度上与以下随机错误有关: 输入图像描述 请注意,XMLHttpRequests(AJAX调用)来自同一域,并且有时不会出现以上错误。 但是,通常它们会执行?

这条消息来自哪个脚本,我该如何修复它? 我只能想到一个可能超过默认最大执行时间的脚本,但是此脚本允许通过页面顶部的ini_set运行更长的时间以达到最大执行时间?

我不知道在哪里查找和修复此问题


1
PHP/JS 代码的例子? - E_p
1
这个问题似乎与你的问题相匹配,并且有几个解决方案 - 你看过了吗? - Don't Panic
1
你使用的 php 版本是什么?你尝试过将 apache.conf 中的 TimeOutProxyTimeout 设置增加到比它们当前值更大的数值吗? - user2560539
这与超时无关,因为它在几次后就可以正常工作。之后我再也没有收到这个警告,直到突然的某个时间。 - TVA van Hesteren
8个回答

31
将以下代码添加到httpd.confapache2.conf文件中(根据您的系统而定):
Timeout 600
ProxyTimeout 600

并重新启动Apache

sudo /etc/init.d/apache2 restart

1
这并不是由于超时造成的,似乎是在服务器非常繁忙时发生的。因为几秒钟/几分钟后脚本可以正常执行? - TVA van Hesteren
{btsdaf} - eselskas
对我没有解决。在Ubuntu上使用Apache 2.4。 - Cary

9

我知道这个问题已经有些年头了,但是当我在WordPress中做多篇文章删除时,我遇到了这个问题,发现很难找到解决方案,所以我将这个问题记录下来(为将来的我和其他遇到同样问题的人)。

对于CentOS 8,请确保已安装fast cgi和可选的php-fph。

yum install mod_fcgid php-fpm

如果没有安装php-fpm,则无需进行编辑:

vi  /etc/httpd/conf.d/fcgid.conf

添加行

FcgidIdleTimeout 1200
FcgidProcessLifeTime 1200
FcgidConnectTimeout 1200
FcgidIOTimeout 1200

如果已经安装了php-fpm,则进行编辑/创建:

vi /etc/httpd/conf.modules.d/00-proxy_timeout.conf

并添加这些行

Timeout 1200
ProxyTimeout 1200

重启php-fpm - 如果已安装并运行httpd。

2

您可以在 ProxyPassMatch 中添加 timeout=

ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1 timeout=1800

请参考这里。希望这能帮到您。


2

这可能对其他人有所帮助。

如果您使用的是Centos 8,我发现以下内容可以解决问题 - 在您的php.conf文件中,在调用SetHandler附近,添加以下内容:

<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch \.(php|phar)$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
  </IfModule>
</IfModule>

<Proxy "unix:/run/php-fpm/www.sock|fcgi://localhost">
    ProxySet connectiontimeout=600 TimeOut=600
</Proxy>

1

我不确定错误是什么,但很可能是您的PHP代码应用程序所花费的时间比配置的时间长。我建议使用CLI版本的PHP进行故障排除。

我可以肯定地说,您的代码卡在某个循环中,请尝试使用CLI版本的PHP,这肯定会有帮助。


0

终于解决了这个问题。

在增加ProxyTimeout后,我开始遇到了这个错误。在我的情况下,问题出在WAF(Web应用程序防火墙)配置上。查看access.log(或your_virtual_host.access.log),我意识到所有源IP都被伪装成防火墙IP而不是来自互联网的真实IP源。更改此配置后,Apache日志开始知道真实的源IP,问题得到解决。


0
我正在使用apache2,发现超时时间为0,所以将其更改为300,根据建议和我们的要求。 超时时间为300。
但是这个选项不可用。 代理超时时间为600。

根据目前的写法,你的回答不够清晰。请编辑以添加更多细节,以帮助其他人理解这如何回答所提出的问题。你可以在帮助中心找到关于如何撰写好回答的更多信息。 - undefined

0
<IfModule reqtimeout_module>

    # mod_reqtimeout limits the time waiting on the client to prevent an
    # attacker from causing a denial of service by opening many connections
    # but not sending requests. This file tries to give a sensible default
    # configuration, but it may be necessary to tune the timeout values to
    # the actual situation. Note that it is also possible to configure
    # mod_reqtimeout per virtual host.


    # Wait max 20 seconds for the first byte of the request line+headers
    # From then, require a minimum data rate of 500 bytes/s, but don't
    # wait longer than 40 seconds in total.
    # Note: Lower timeouts may make sense on non-ssl virtual hosts but can
    # cause problem with ssl enabled virtual hosts: This timeout includes
    # the time a browser may need to fetch the CRL for the certificate. If
    # the CRL server is not reachable, it may take more than 10 seconds
    # until the browser gives up.
    RequestReadTimeout header=20-40,minrate=500

    # Wait max 10 seconds for the first byte of the request body (if any)
    # From then, require a minimum data rate of 500 bytes/s
    RequestReadTimeout body=10,minrate=500

</IfModule>

以上似乎是Debian的默认设置 - 在我的情况下,我只需要修改这些值来增加预设的超时时间。


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