1. 程式人生 > 實用技巧 >Apache如何設定Enable Keep-Alive

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.

  做效能優化的朋友可以試試