背景:
我有机器对机器的通信系统,客户端不时向Apache服务器发送数据。由于使用移动 2G 进行通信,因此通信速度很慢。Apache 使用 mod_wsgi(用于 Django)。
由于客户端在开始通信时不知道实际数据量,因此客户端和服务器之间使用分块传输编码。因为 mod_wsgi 不支持分块传输编码,所以我使用 mod_proxy,它接收块并将它们作为单个请求传递给 mod_wsgi,并在收到所有数据后添加内容长度信息。
问题:
我将服务器上的 Ubuntu 从 16.04 更新到 18.04,之后客户端和服务器之间的一些通信开始失败。从 Apache 的 access.log 中,我可以看到,该服务器使用“大”数据向客户端响应 408。大意味着在这种情况下数据量需要大约 60 秒的时间进行传输。客户端没有任何变化。
我了解到,对于 Apache 2.4(我在服务器的 Ubuntu 18.04 上拥有)TimeOut 是 60 秒,对于早期的 Apache 版本它是 300 秒。我想这是在“大”数据的情况下与新服务器操作系统通信失败的原因。
边注:
我注意到启用 mod_security 可以解决问题(没有“大”数据的 408),但就在我禁用 mod_security 并重新启动 Apache 时,408 返回图片。security.conf 中没有与超时相关的内容。
问题:
如何正确增加 TimeOut?
到目前为止尝试过:
由于 Apache 真的不是我的核心能力,我一直在尝试将 Timeout 增加到某些地方(也尝试过 KeepAliveTimeout,即使我认为这不是正确的方法):
apache.conf 片段:
#
# 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 片段:
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