AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 21447
Accepted
Simon Foster
Simon Foster
Asked: 2009-06-08 02:53:16 +0800 CST2009-06-08 02:53:16 +0800 CST 2009-06-08 02:53:16 +0800 CST

Apache gzip 配置

  • 772

我的服务器上安装了 apache 2.2.11,我一直在尝试根据 yslow firefox 插件的建议来减少网站页面的加载时间。

我已经配置了 gzip 和 etag 以及它的一些其他建议,但我注意到在我的 css 文件的标题中,etag 被附加了文本 gzip。

有谁知道为什么以及如何解决这个问题?

我服务器的标头
日期 2009 年 6 月 7 日星期日 10:40:57 GMT
服务器 Apache/2.2.11 (Fedora)
最后修改时间 2009 年 5 月 31 日星期日 15:06:38 GMT
Etag“3b4-46b36a802bb80”-gzip
接受范围字节
缓存控制 max-age=2592000
2009 年 7 月 7 日星期二 10:40:57 GMT
改变接受编码
内容编码 gzip
内容长度 530
连接关闭
内容类型文本/css

我的托管包上的相同代码使用旧版本的 apache,并且没有相同的问题。这可能只是一个apache错误吗?

我的托管包中的标题
日期 2009 年 6 月 7 日星期日 10:48:26 GMT
服务器 Apache/2.0.63 (FreeBSD) mod_python/3.3.1 Python/2.5.1 PHP/5.2.6 with Suhosin-Patch mod_fastcgi/2.4.6 mod_ssl/2.0.63 OpenSSL/0.9.7e-p1 DAV/2 mod_perl/ 2.0.4 Perl/v5.8.8
最后修改时间 2009 年 2 月 21 日星期六 13:54:52 GMT
电子标签“3b4-1d104300”
接受范围字节
缓存控制 max-age=2592000
2009 年 7 月 7 日星期二 10:48:26 GMT
改变接受编码
内容编码 gzip
内容长度 530
连接关闭
内容类型文本/css
linux apache-2.2 web-hosting
  • 3 3 个回答
  • 3473 Views

3 个回答

  • Voted
  1. Best Answer
    Samuel Parkinson
    2009-06-08T05:05:02+08:002009-06-08T05:05:02+08:00

    这是一个理想的 .htaccess,它既可以压缩又可以设置合适的过期标头。

    # Insert filter
    SetOutputFilter DEFLATE
    
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    
    # MSIE masquerades as Netscape, but it is fine
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
    
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresDefault "access plus 1 seconds"
      ExpiresByType image/x-icon "access plus 2592000 seconds"
      ExpiresByType image/jpeg "access plus 2592000 seconds"
      ExpiresByType image/png "access plus 2592000 seconds"
      ExpiresByType image/gif "access plus 2592000 seconds"
      ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
      ExpiresByType text/css "access plus 604800 seconds"
      ExpiresByType text/javascript "access plus 216000 seconds"
      ExpiresByType application/x-javascript "access plus 216000 seconds"
      ExpiresByType text/html "access plus 600 seconds"
      ExpiresByType application/xhtml+xml "access plus 600 seconds"
    </IfModule>
    
    <IfModule mod_headers.c>
      <FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
        Header set Cache-Control "max-age=2592000, public"
      </FilesMatch>
      <FilesMatch "\\.(css)$">
        Header set Cache-Control "max-age=604800, public"
      </FilesMatch>
      <FilesMatch "\\.(js)$">
        Header set Cache-Control "max-age=216000, private"
      </FilesMatch>
      <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
      </FilesMatch>
    </IfModule>
    
    <IfModule mod_headers.c>
      Header unset ETag
    </IfModule>
    FileETag None
    
    <IfModule mod_headers.c>
      Header unset Last-Modified
    </IfModule>
    

    以下文章介绍了它的作用并讨论了压缩:

    http://www.samaxes.com/2009/01/06/more-on-compressing-and-caching-your-site-with-htaccess/

    希望有帮助。

    • 4
  2. null
    2015-11-13T06:33:25+08:002015-11-13T06:33:25+08:00

    Apachemod_deflate正在为每个实体创建唯一的 Etag,因为它们标识了 URL 的特定实体变体。每个协商的变体都需要有唯一的 ETag:s。因为mod_deflate它就像将编码添加到已经计算的 ETag 一样简单。

    一种解决方法是从 Etag 中删除编码:

    <Location /js>
      RequestHeader  edit "If-None-Match" "^(.*)-gzip$" "$1"
      Header  edit "ETag" "^(.*[^g][^z][^i][^p])$" "$1-gzip"
    </Location>
    

    如果您将 Apache 2.5 与该mod_deflate模块一起使用,则可以使用该指令DeflateAlterETag指定在压缩响应时应如何更改 ETag hader。

    DeflateAlterETag AddSuffix|NoChange|Remove
    

    来源:https ://httpd.apache.org/docs/trunk/mod/mod_deflate.html#deflatealteretag

    这篇博文建议完全删除 Etags 并依赖Cache-Control标头。

    要做到这一点httpd.conf:

    <IfModule mod_headers.c>
        Header unset ETag
    </IfModule>
    
    FileETag None
    

    请注意,如果实体 gzip:ed bymod_deflate仍然带有与普通实体相同的 ETag,这可能会导致 ETag 感知代理缓存中的不一致。

    更多信息在这里:

    • https://bz.apache.org/bugzilla/show_bug.cgi?id=45023
    • https://bz.apache.org/bugzilla/show_bug.cgi?id=45023
    • 2
  3. Brent Ozar
    2009-06-08T04:33:21+08:002009-06-08T04:33:21+08:00

    你能详细说明你是如何配置gzip的吗?例如,您是否使用 mod_deflate?您可以从您的 httpd.conf 中发布片段,尤其是 AddOutputFilterByType 字段吗?我为我的特定托管服务提供商遵循了这些指示,并且 text/css 可能不在您的托管服务提供商的列表中:

    http://kb.mediatemple.net/questions/1567/Compressing+web+pages+with+mod_deflate

    • 0

相关问题

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • mod_rewrite 不转发 GET 参数

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve