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

  如果找不到文件,可以用这个命令来查找

find / -name httpd.conf

  

  当然您可以调整具体的参数,可参考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.

  如果是用宝塔的话直接编辑/www/server/apache/conf/extra/httpd-default.conf

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

posted @ 2020-07-24 09:23  ytkah  阅读(307)  评论(0编辑  收藏  举报
IPO发家故事 网址导航 gg N / G Sitemap

部分内容来源于网络,如有版权问题请联系删除