响应头 - 连接:保持活动,关闭

时间:2014-03-12 13:30:02

标签: .htaccess response-headers

我正在努力提高页面速度,建议让Connection:Keep-alive。然而,无论我尝试做什么,我都有"保持活力,关闭"。我无法找到"关闭"价值来自。

我也不能删除它。有人经历过同样的事情吗?

我的.htaccess中有这个:

    标题集连接保持活动状态

祝你好运, 拉斯穆斯

1 个答案:

答案 0 :(得分:1)

您的服务器似乎已禁用您的帐户或整个服务器的保持活动状态,以确保Rasmus始终可以使用最大套接字数。

这当然是一把双刃剑,因为大多数网站在提取构建页面所需的所有资源时通常会产生10-30个请求,而不会缓存任何内容,这会产生大量的开放和结束开销。即使它需要下载50个额外的资源,设置如下:

<ifModule mod_headers.c>
    Header set Connection keep-alive
    Keep-Alive: timeout=5, max=100
</ifModule>

将有足够的时间来完成工作。但我确定禁用此功能的标准做法是确保它不会被滥用。只要问你的管理员他们是否可以帮你。

我的建议是不要担心Keep-Alive标题,无论如何都要确保正确缓存静态文件,这样你就可以获得更多好处。如果您的管理员为您提供了很好的帮助,但这就是我在.htaccess文件中添加的内容,以帮助将收到的请求数量减少60%-80%。

<IfModule mod_expires.c>
    # Enable expiration control
    ExpiresActive On

    # Default expiration: 1 hour after request
    ExpiresDefault "now plus 1 hour"

    # CSS and JS expiration: 1 week after request
    ExpiresByType text/css "now plus 1 week"
    ExpiresByType application/javascript "now plus 1 week"
    ExpiresByType application/x-javascript "now plus 1 week"

    # Image files expiration: 1 month after request
    ExpiresByType image/bmp "now plus 1 month"
    ExpiresByType image/gif "now plus 1 month"
    ExpiresByType image/jpeg "now plus 1 month"
    ExpiresByType image/jp2 "now plus 1 month"
    ExpiresByType image/pipeg "now plus 1 month"
    ExpiresByType image/png "now plus 1 month"
    ExpiresByType image/svg+xml "now plus 1 month"
    ExpiresByType image/tiff "now plus 1 month"
    ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
    ExpiresByType image/x-icon "now plus 1 month"
    ExpiresByType image/ico "now plus 1 month"
    ExpiresByType image/icon "now plus 1 month"
    ExpiresByType text/ico "now plus 1 month"
    ExpiresByType application/ico "now plus 1 month"
    ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
    ExpiresByType application/vnd.wap.wbxml "now plus 1 month"
    ExpiresByType application/smil "now plus 1 month"

    # Audio files expiration: 1 month after request
    ExpiresByType audio/basic "now plus 1 month"
    ExpiresByType audio/mid "now plus 1 month"
    ExpiresByType audio/midi "now plus 1 month"
    ExpiresByType audio/mpeg "now plus 1 month"
    ExpiresByType audio/x-aiff "now plus 1 month"
    ExpiresByType audio/x-mpegurl "now plus 1 month"
    ExpiresByType audio/x-pn-realaudio "now plus 1 month"
    ExpiresByType audio/x-wav "now plus 1 month"

    # Movie files expiration: 1 month after request
    ExpiresByType application/x-shockwave-flash "now plus 1 month"
    ExpiresByType x-world/x-vrml "now plus 1 month"
    ExpiresByType video/x-msvideo "now plus 1 month"
    ExpiresByType video/mpeg "now plus 1 month"
    ExpiresByType video/mp4 "now plus 1 month"
    ExpiresByType video/quicktime "now plus 1 month"
    ExpiresByType video/x-la-asf "now plus 1 month"
    ExpiresByType video/x-ms-asf "now plus 1 month"
</IfModule>