尝试在 Apache 上使用 GZip 时出现内容编码错误

我正在尝试在我的网络服务器上启用 Gzip,但没有成功。 当然,我现在需要,我以前做过,但成功阻碍了我。

我的 httpd.conf 中有这个

<Location "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/bt/web">
    # 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

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
</Location>

<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|html|htm)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

mod_deflate 已启用。

我在做什么不正确?

1
2022-06-07 15:17:44
资源 分享
答案: 1

第一个问题是你有一个来自文档系统的目录的方面

这是来自 Apache 手册:

何时使用 <Location>。 使用 <Location> 对位于文件系统之外的 Web 内容使用指令。 对于保留在文件系统中的内容,请使用 <Directory><Files>。 一个例外是 <Location />,这是一种对整个 Web 服务器使用配置的简单方法。

当我在 Apache 上安排 mod_deflate 时,我使用以下设置:

# --------------------------------------------------------
# Deflate Module Configuration
# --------------------------------------------------------
<IfModule deflate_module>
  # Set the location to webservers root
  <Location />
    # Insert the filters
    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

    # Make sure to never zip binaries (ie6 and chrome has issues with this.)
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
  </Location>

    # Enable mod_deflate logging by uncommenting these lines
    #DeflateFilterNote Input instream
    #DeflateFilterNote Output outstream
    #DeflateFilterNote Ratio ratio

    #LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    #CustomLog logs/deflate_log deflate 
</IfModule>
1
2022-06-07 19:21:17
资源