首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在使用mod_proxy时正确地增加Apache的超时

如何在使用mod_proxy时正确地增加Apache的超时
EN

Server Fault用户
提问于 2020-11-03 09:34:12
回答 1查看 8.4K关注 0票数 1

背景:

我有机器对机器的通信系统,客户端不时地将数据发送到Apache。通信速度慢,因为移动2G用于通信。Apache使用mod_wsgi (用于Django)。

由于客户端在通信启动时不知道实际数据量,所以在客户端和服务器之间使用分组传输编码。由于mod_wsgi不支持分组传输编码,所以我使用mod_proxy,它接收块并将它们作为单个请求传递给mod_wsgi,在接收到所有数据时添加内容长度信息。

问题:

我将服务器上的Ubuntu从16.04更新到18.04,之后客户机和服务器之间的一些通信开始失败。从Apache的access.log中我可以看到,服务器用“大”数据响应客户端408。这意味着在这种情况下,数据数量大约需要60秒才能传输。客户端没有任何变化。

我已经了解到,对于Apache2.4(我在服务器的Ubuntu18.04上),TimeOut是60秒,而早期的Apache2.4是300秒。我想这就是在“大”数据情况下与新服务器操作系统通信失败的原因。

旁注:

我已经注意到启用mod_security解决了这个问题(没有408有“大”数据),但就在我禁用mod_security并重新启动Apache时,408返回到了图片。security.conf中没有与超时相关的内容。

问题:

如何正确提高TimeOut?

已经尝试过了:

由于Apache确实不是我的核心能力,所以我一直试图在一些地方增加超时时间(我也尝试过KeepAliveTimeout,即使我认为它不正确):

apache.conf片段:

代码语言:javascript
运行
复制
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 300

example.com.conf片段:

代码语言:javascript
运行
复制
ProxyRequests Off
ProxyTimeout 300

<Proxy http://example.com:81>
        Order deny,allow
        Allow from all
</Proxy>

<VirtualHost *:80>
        SetEnv proxy-sendcl 1
        ProxyPass / http://example.com:81/ connectiontimeout=300 timeout=300
        ProxyTimeout 300
        ProxyPassReverse / http://example.com:81/
        ProxyPreserveHost On
        ProxyVia Full

        <Directory proxy:*>
                Order deny,allow
                Allow from all
        </Directory>
</VirtualHost>

Listen 81

<VirtualHost *:81>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName example.com
EN

回答 1

Server Fault用户

回答已采纳

发布于 2020-11-03 10:01:51

您确定408错误是由于Apache服务请求所花费的时间太长了吗?

HTTP 408是“请求超时”。当客户端连接,但在超时触发器之前没有发送任何数据时,就会发生这种情况。您可以在接收请求之前使用ReqTimeout模块(https://httpd.apache.org/docs/2.4/mod/mod_reqtimeout.html)来增加超时。请记住,通过增加超时,您将有更多的apache进程忙于从客户端等待删除或使用套接字。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1041082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档