How can I enable keep-alive?

后端 未结 6 1085
醉酒成梦
醉酒成梦 2020-12-28 13:21

I ran a Google Page Speed and it says I scored 57/100 because I need to \"Enable Keep-Alive\" and \"Enable Compression\". I did some Google searches but I c

相关标签:
6条回答
  • 2020-12-28 13:47

    Configure Apache KeepAlive settings

    Open up apache’s configuration file and look for the following settings. On Centos this file is called httpd.conf and is located in /etc/httpd/conf. The following settings are noteworthy:

    • KeepAlive: Switches KeepAlive on or off. Put in “KeepAlive on” to turn it on and “KeepAlive off” to turn it off.

    • MaxKeepAliveRequests: The maximum number of requests a single persistent connection will service. A number between 50 and 75 would be plenty.

    • KeepAliveTimeout: How long should the server wait for new requests from connected clients. The default is 15 seconds which is way too high. Set it to between 1 and 5 seconds to avoid having processes wasting RAM while waiting for requests.

    Read more about benefits of keep alive connection here: http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

    0 讨论(0)
  • 2020-12-28 13:47

    To enable keep-alive through .htaccess you need to add the following code to your .htaccess file:

    <ifModule mod_headers.c>
        Header set Connection keep-alive
    </ifModule>
    
    0 讨论(0)
  • 2020-12-28 13:54

    Keep-alive is using the same tcp connection for HTTP conversation instead of opening new one with each new request. You basically need to set HTTP header in your HTTP response

    Connection: Keep-Alive
    

    Read more here

    0 讨论(0)
  • 2020-12-28 13:57

    To enable KeepAlive configuration, Go to conf/httpd.conf in Apache configuration and set the below property : KeepAlive On

    0 讨论(0)
  • 2020-12-28 14:01

    When you have "keep-alive" enabled you tell the browser of your user to use one TCP/IP connection for all the files(images, scripts,etc.) your website loads instead of using a TCP/IP connection for every single file. So it keeps a single connection "alive" to retrieve all the website files at once. This is much faster as using a multitude of connections. There are various ways to enable keep-alive. You can enable it by

    • Using/Editing the .htaccess file
    • Enabling it through access to your web server(Apache, Windows server, etc.)

    Go here for more detailed information about this.

    With the "Enable Compression" part they mean you should enable GZIP compression (if your web host hasn't already enabled it, as it's pretty much the default nowadays). The GZIP compression technique makes it possible for your web files to be compressed before they're being sent to your users browser. This means your user has to download much smaller files to fully load your web pages.

    0 讨论(0)
  • 2020-12-28 14:09

    I had the same problem and after a bit of research I found that the two most popular ways to do it are:

    1. If you do not have access to your webserver config file you can add HTTP headers yourself using a .htaccess file by adding this line of code:

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

    2. If you are able to access your Apache config file, you can turn on keep-alive there by changing these 3 lines in httpd.conf file found here /etc/httpd/conf/

      KeepAlive On

      MaxKeepAliveRequests 0

      KeepAliveTimeout 100

    You can read more from this source which explains it better than me https://varvy.com/pagespeed/keep-alive.html

    0 讨论(0)
提交回复
热议问题