Apache如何设置Enable Keep-Alive

时间:2022-07-23
本文章向大家介绍Apache如何设置Enable Keep-Alive,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

  在优化网站性能的时候,我们会发现有些站点的Enable Keep-Alive分数很低,如何调整设置呢?HTTP持久连接(英语:HTTP persistent connection,也称作HTTP keep-alive或HTTP connection reuse)是使用同一个TCP连接来发送和接收多个HTTP请求/应答,而不是为每一个新的请求/应答打开新的连接的方法。如何设置Keep-Alive呢?随ytkah一起来看看,以Apache为例

  1、如果您无权访问Web服务器配置文件,则可以通过在.htaccess文件添加以下代码行来实现添加HTTP标头:

<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>

  2、如果您能够访问您的Apache配置文件,则可以通过在/ etc / httpd / conf /中找到的httpd.conf文件中的这3行更改来打开保持活动状态。

KeepAlive On
MaxKeepAliveRequests 0
KeepAliveTimeout 100

  当然您可以调整具体的参数,可参考https://www.giftofspeed.com/enable-keep-alive/

– KeepAlive: Set it to "KeepAlive on" to enable keep-alive. To disable it use "KeepAlive off". – MaxKeepAliveRequests: Sets the maximum number of requests for every keep-alive connection. A good number to start with is 60 requests per connection. – KeepAliveTimeout: Sets how long your server should wait for new requests from clients. The 15 second default is too high. Set it to 3 seconds to start with and gradually go up when it underperforms. Setting it to a lower amount of seconds results in less parallel connections which again results in less server load.

  做性能优化的朋友可以试试