.htaccess htaccess中的gzip压缩代码不工作
我想使用gzip压缩压缩我的网页内容,为此,我在.htaccess文件中使用了以下代码,但它不起作用.htaccess htaccess中的gzip压缩代码不工作,.htaccess,compression,gzip,.htaccess,Compression,Gzip,我想使用gzip压缩压缩我的网页内容,为此,我在.htaccess文件中使用了以下代码,但它不起作用 # BEGIN Compress text files <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$
# BEGIN Compress text files
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# END Compress text files
#开始压缩文本文件
mod_gzip_on Yes
是的
mod_gzip_item_include file\(html?| txt | css | js | php | pl)$
mod_gzip_item_包含处理程序^cgi脚本$
mod_gzip_项目包括mime^text/*
mod_gzip_item_包括mime^application/x-javascript*
mod_gzip_项_排除mime^image/*
mod_gzip_item_排除rspheader^内容编码:.*gzip*
#结束压缩文本文件
我正在使用测试gzip压缩,但是这个工具告诉我,我的网页中没有gzip压缩
我的代码有什么问题吗?或者问题出在别的地方 #480周
# 480 weeks
#######################################
### Apache configuration directives ###
### for mod_gzip 1.3.26.1a ###
#######################################
##########################
### loading the module ###
##########################
# ---------------------------------------------------------------------
# load DLL / Win32:
# LoadModule gzip_module modules/ApacheModuleGzip.dll
#
# load DSO / UNIX:
# LoadModule gzip_module modules/mod_gzip.so
#
# (none of both if module has been compiled in statically;
# the exact file name may depend upon the exact compilation method used
# for this module)
# ---------------------------------------------------------------------
<ifModule mod_gzip.c>
########################
### responsibilities ###
########################
# ---------------------------------------------------------------------
# use mod_gzip at all?
mod_gzip_on Yes
# (you can especially enable mod_gzip inside the central server
# configuration but disable it inside some directories ot virtual
# hosts by using this directive.)
# ---------------------------------------------------------------------
######################################
### statically precompressed files ###
######################################
# ---------------------------------------------------------------------
# let mod_gzip perform 'partial content negotiation'?
mod_gzip_can_negotiate Yes
# (if this option is active and a static file is to be served in com-
# pressed for, then mod_gzip will look for a static precompressed
# version of this file with a defined additional extension - see next
# directive - which would be delivered with priority. This would allow
# for avoiding to repeatedly compress the same static file and thus
# saving CPU time.
# No dynamic caching of this file is provided; currently the user
# himself is responsible for creating and updating the precompressed
# file's content.
# From version 1.3.19.2a mod_gzip automatically recognizes whether
# a statically precompressed file is older than its uncompressed
# original and in this case will serve the content of the original
# file in uncompressed form - as to rather serve correct data than
# outdated ones ...)
# ---------------------------------------------------------------------
# extension (suffix) for statically precompressed files
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
# (effect: see previous directive; this string will be appended to the
# name of the original file.
# be sure to configure the encoding 'gzip' for this extension as well,
# because mod_gzip doesn't serve the content itself but simply generates
# an Apache internal redirection to this URL. Therefore the remaining
# Apache configuration is responsible for setting the 'Content-Encoding'
# header properly ...
# prior to version 1.3.19.2a this value was not configurable.)
# ---------------------------------------------------------------------
# automatic updates for statically precompressed files
mod_gzip_update_static No
# (if set to 'Yes', this directive (being new in version 1.3.26.1a) would
# cause mod_gzip to automatically update an outdated version of any
# statically precompressed file during the request, i. e. compress the
# originally requested file and overwrite the precompressed variant
# file with it!
# for each automatic update of this type, mod_gzip will write a message
# of the severity 'notice' into the Apache error_log.
# while doing so, mod_gzip will directly read the original file's content.
# therefore this content cannot be interpreted by any other Apache module
# during the request. this might possibly not be what you want - hopefully
# it will be what most users want, because it works fast this way.
# use this configuration with a lot of care, and be sure that you don't
# inadvertantly cause valuable files within the URL tree to be overwritten.
# this isn't a feature to be used for mass hosting servers, especially
# because mod_gzip might experience access control problems there - the
# userid the Apache processes are running under need to have write access
# to the precompressed files of all users, which may not automatically be
# the case.)
# [mod_gzip error handling in this situation??? what will be served?]
# ---------------------------------------------------------------------
###################
### bureaucracy ###
###################
# ---------------------------------------------------------------------
# display status for mod_gzip
mod_gzip_command_version '/mod_gzip_status'
# (defines an URL to display the status of mod_gzip; can be specified
# individually for each installation and protected against access via
# <location> section for privacy reasons)
# ---------------------------------------------------------------------
# The status display will look like this:
# mod_gzip is available...
# mod_gzip_version = 1.3.26.1a
# mod_gzip_on = Yes/No
# and thus will provide information about
# - mod_gzip being installed at the server and working correctly,
# - which version has been installed and
# - whether mod_gzip has been set 'active' for this Location
# (-> mod_gzip_on)
# ---------------------------------------------------------------------
#######################
### data management ###
#######################
# ---------------------------------------------------------------------
# Working directory for temporary files and the compression cache
# if not specified, the following default values are used:
# [Win32=c:temp], [UNIX=/tmp]
# mod_gzip_temp_dir /tmp
# (This directory must already exist and the userid being used for
# running the Apache server must have read and write access to this
# directory.
# Unlike other Apache directives an absolute path name must be specified
# here; a relative value will not be interpreted relatively to ServerRoot.
# This pastname must NOT be terminated with '/'.
# For maximum performance this directory should be located on a RAM disk,
# if the file system isn't already being cached efficiently
# ---------------------------------------------------------------------
# Save temporary work files [Yes, No]
mod_gzip_keep_workfiles No
# (one file per HTTP request - set to 'yes' for debugging purpose only!)
# ---------------------------------------------------------------------
##################
### file sizes ###
##################
# ---------------------------------------------------------------------
# minimum size (in bytes) for files to be compressed
mod_gzip_minimum_file_size 500
# (for very small files compression will produce only small absolute gains
# [you will still save about 50% of the content, but some additional
# 500 bytes of HTTP and TCP headers will always remain uncompressed],
# but still produce CPU load for both client and server.
# mod_gzip will automatically set smaller values than 300 bytes for
# this directive to exactly this value 300.)
# ---------------------------------------------------------------------
# maximum size (in bytes) for files to be compressed
mod_gzip_maximum_file_size 500000
# (for very large files compression may eventually take rather long and
# thus delay the start of the transmission.
# Furthermode a limitation at this point prevents the server from
# producing output of unlimited size in case of some endless loop
# inside a CGI script - or even trying to compress streaming data -
# which might otherwise cause the creation of a temporary file of
# any size and even fill up the whole hard disk.
# On the other hand, compression will have a much more perceivable
# subjective effect for large files ... so be sure to fine-tune this
# according to your requirements.)
# ---------------------------------------------------------------------
# maximum size (in bytes) for files to be compressed in memory
mod_gzip_maximum_inmem_size 60000
# (larger files will be compressed into the temp file directory; adapt
# this value to your server's available main memory.
# In mod_gzip 1.3.19.x larger values will automatically be limited to
# 60000 because some operating systems are said to have problems
# allocating more than 64 kb of memory at a time.
# ---------------------------------------------------------------------
####################
### requirements ###
####################
# (see chapter about caching for problems when using these directives.)
# ---------------------------------------------------------------------
# Required HTTP version of the client
# Possible values: 1000 = HTTP/1.0, 1001 = HTTP/1.1, ...
# This directive uses the same numeric protocol values as Apache does
# internally
mod_gzip_min_http 1000
# (By using this directive you may exclude old browsers, search engines
# etc. from the compression procedure: if the user agent doesn't
# declare itself capable of understanding at least the HTTP level
# specified here, only uncompressed data will be delivered - no matter
# what else it claims to be able to. The value of '1001' will especially
# exclude Netscape 4.x. and a lot of proxy servers.)
# ---------------------------------------------------------------------
# HTTP methods to be handled
# Possible values: 'GET', 'POST' or a list of both values.
mod_gzip_handle_methods GET POST
# (By using this directive you may particularly exclude POST requests
# from the compression procedure. There are known cases where the
# handling of these requests by previous mod_gzip versions could cause
# problems.
# Before version 1.3.19.2a this value was not configurable.)
# ---------------------------------------------------------------------
###############
### filters ###
###############
# ---------------------------------------------------------------------
# which files are to be compressed?
#
# The order of processing during each of both phases is not important,
# but to trigger the compression of a request's content this request
# a) must match at least one include rule in each of both phases and
# b) must not match an exclude rule in any of both phases.
# These rules are not minimal, they are meant to serve as example only.
#
# Note that all parameter values of the directives in this section are
# evaluated as regular expressions, and not in a case-sensitive way.
# ---------------------------------------------------------------------
# phase 1: (reqheader, uri, file, handler)
# ========================================
# NO: special broken browsers which request for gzipped content
# but then aren't able to handle it correctly
mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"
# From version 1.3.19.2a on I advise against using filters
# for User-agents, as this will cause HTTP-Headers 'Vary: User-Agent'
# to be generated, thus making life more difficult for proxy servers.
#
# JA: HTML-Dokumente
mod_gzip_item_include file .html$
#
# NO: include files / JavaScript & CSS (due to Netscape4 bugs)
mod_gzip_item_exclude file .js$
mod_gzip_item_exclude file .css$
#
# YES: CGI scripts
mod_gzip_item_include file .pl$
mod_gzip_item_include handler ^cgi-script$
#
# phase 2: (mime, rspheader)
# ===========================
# YES: normal HTML files, normal text files, Apache directory listings
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include mime ^httpd/unix-directory$
#
# NO: images (GIF etc., will rarely ever save anything)
mod_gzip_item_exclude mime ^image/
# ---------------------------------------------------------------------
# In fact mod_gzip is checking only the first 4 characters of the 1st
# operand (in case of uri even the first 2 characters only, as to
# allow for values like url).
# ---------------------------------------------------------------------
# The table for mod_gzip_item rules (include and exclude) cannot contain
# more than 256 entries; when this number is exceeded mod_gzip will
# output the message "mod_gzip: ERROR: Item index is full"
# and report a configuration error to the Apache server.
# ---------------------------------------------------------------------
# The directive values described here are meant to describe the requests
# elected for compression most exactly.
# Especially for the mime rules it has to be made clear that the HTTP
# header 'Content-Type' (that will be checked by mod_gzip for this rule)
# in some cases may contain not only a MIME type but additionally a
# character set description (charset) as well.
# If this is the case for the requests to be handled then you need to
# remove the '$' char at the end of the corresponding value so that now
# only the prefix of this value will be tested for matching.
# ---------------------------------------------------------------------
##########################
### transfer encodings ###
##########################
# ---------------------------------------------------------------------
# Allow mod_gzip to eliminate the HTTP header
# 'Transfer-encoding: chunked'
# and join the chunks to one (compressable) packet
mod_gzip_dechunk Yes
# (this is required for handling several types of dynamically generated
# contents, especially for CGI and SSI pages, but also for pages produced
# by some Java Servlet interpreters.
# ---------------------------------------------------------------------
###############
### logging ###
###############
# ---------------------------------------------------------------------
# Extended log format (for testing the compression effect)
LogFormat "%h %l %u %t "%V %r" %<s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n -< Out:%{mod_gzip_output_size}n = %{mod_gzip_compression_ratio}n pct." common_with_mod_gzip_info2
# ---------------------------------------------------------------------
# Create additional log file
CustomLog logs/mod_gzip.log common_with_mod_gzip_info2
# (surely you can redefine your normal log file format, but you mal well
# keep its format standard compatible for evaluation by standard web
# analysis tools. So we just create another log file.)
# ---------------------------------------------------------------------
# Volume computation of the delivered files inside the Apache access_log:
# count HTTP header size (in bytes) as part of total output size
mod_gzip_add_header_count Yes
# (This will be more than the pure document content, but it will more
# realistically describe the total output traffic of the HTTP request)
# ---------------------------------------------------------------------
###############
### proxies ###
###############
# ---------------------------------------------------------------------
# sending a 'Vary' HTTP header
mod_gzip_send_vary On
# (see chapter about caching for this directive.)
# don't change this unless you absolutely know what you are doing!
# ---------------------------------------------------------------------
</ifModule>
#######################################
###Apache配置指令###
###适用于mod_gzip 1.3.26.1a###
#######################################
##########################
###加载模块###
##########################
# ---------------------------------------------------------------------
#加载DLL/Win32:
#LoadModule gzip_modules/apachemoulegzip.dll
#
#加载DSO/UNIX:
#LoadModule gzip_modules/mod_gzip.so
#
#(如果模块已静态编译,则两者均不存在;
#确切的文件名可能取决于使用的确切编译方法
#(适用于本模块)
# ---------------------------------------------------------------------
########################
###责任###
########################
# ---------------------------------------------------------------------
#使用mod_gzip吗?
mod_gzip_on Yes
#(您尤其可以在中央服务器内启用mod_gzip
#配置,但在某些虚拟目录中禁用它
#通过使用此指令创建主机。)
# ---------------------------------------------------------------------
######################################
###静态预压缩文件###
######################################
# ---------------------------------------------------------------------
#让mod_gzip执行“部分内容协商”?
mod_gzip_能协商吗
#(如果此选项处于活动状态,并且要在com中提供静态文件-
#按下for,则mod_gzip将查找静态预压缩
#具有定义的附加扩展名的此文件的版本-请参阅下一步
#指令-将优先交付。这将允许
#避免重复压缩同一静态文件,从而
#节省CPU时间。
#未提供此文件的动态缓存;当前用户
#他自己负责创建和更新预压缩
#文件的内容。
#从1.3.19.2a版开始,mod_gzip自动识别
#静态预压缩的文件比未压缩的文件旧
#原件,在这种情况下,将提供原件的内容
#未压缩格式的文件-用于提供正确的数据而不是
#过时的…)
# ---------------------------------------------------------------------
#静态预压缩文件的扩展名(后缀)
mod_gzip_static_suffix.gz
AddEncoding gzip.gz
#(效果:请参见前面的指令;此字符串将附加到
#原始文件的名称。
#还要确保为此扩展配置编码“gzip”,
#因为mod_gzip不提供内容本身,而只是生成
#Apache内部重定向到此URL。因此
#Apache配置负责设置“内容编码”
#标题正确。。。
#在版本1.3.19.2a之前,此值不可配置。)
# ---------------------------------------------------------------------
#静态预压缩文件的自动更新
mod_gzip_update_静态编号
#(如果设置为“是”,则本指令(版本1.3.26.1a中的新指令)将
#使mod_gzip自动更新任何
#在请求期间静态预压缩的文件,即压缩
#最初请求的文件,并覆盖预压缩变量
#归档!
#对于这种类型的每次自动更新,mod_gzip都会编写一条消息
#将严重性“通知”写入Apache错误日志。
#在执行此操作时,mod_gzip将直接读取原始文件的内容。
#因此,任何其他Apache模块都无法解释此内容
#在请求期间。这可能不是您想要的-希望如此
#这将是大多数用户想要的,因为它以这种方式工作得很快。
#使用此配置时要非常小心,并确保您不会
#无意中导致URL树中有价值的文件被覆盖。
#这不是一个用于大规模托管服务器的功能,尤其是
#因为mod_gzip可能会遇到访问控制问题,所以
#运行Apache进程的用户ID需要具有写访问权限
#到所有用户的预压缩文件,可能不会自动
#(案例)
#[mod_gzip在此情况下的错误处理???将提供什么服务?]
# ---------------------------------------------------------------------
###################
###官僚主义###
###################
# ---------------------------------------------------------------------
#显示mod_gzip的状态
mod_gzip_命令版本'/mod_gzip_状态'
#(定义显示mod_gzip状态的URL;可以指定。)
#每个安装都单独安装,并防止通过
#(隐私原因部分)
# ---------------------------------------------------------------------
#状态显示将如下所示:
#mod_gzip可用。。。
#mod_gzip_版本=1.3.26.1a
#mod_gzip_on=是/否
#并将提供有关
#-mod_gzip安装在服务器上并正常工作,
#-安装了哪个版本,以及
#-mod_gzip是否已设置为“激活”