鉴于本版不少人问mod_gzip和mod_perl的配置问题,特发此贴

fzjw 2005-06-22 06:02:46
今天在自己机器上换了Apache 2.0.54,成功配置mod_gzip和mod_perl,分享一下经验 :)

Apache2吃内存太凶,比1.3.33厉害多了 -_-#

言归正传......

软件版本:
Apache2 : 2.0.54
Perl : 5.8.7
mod_perl : 2.0.1
mod_gzip : 2.0.50

1、mod_gzip 2.0.50

下载mod_gzip

for Apache1:
http://www.gknw.net/development/apache/apache-1.3/win32/modules/mod_gzip-1.3.19.1a-w32.zip
http://www.gknw.net/development/apache/apache-1.3/win32/modules/mod_gzip-1.3.19.2a-w32.zip
http://www.gknw.net/development/apache/apache-1.3/win32/modules/mod_gzip-1.3.26.1a-EAPI-w32.zip
http://www.gknw.net/development/apache/apache-1.3/win32/modules/mod_gzip-1.3.26.1a-w32.zip

for Apache2:
http://www.gknw.net/development/apache/httpd-2.0/win32/modules/mod_gzip-2.0.49-w32.zip
http://www.gknw.net/development/apache/httpd-2.0/win32/modules/mod_gzip-2.0.53-w32.zip


编辑httpd.conf:

LoadModule gzip_module modules/mog_gzip.so

AddModule mod_gzip.c (Apache2不需要这行)

<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!)
# ---------------------------------------------------------------------
...全文
280 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
MPU 2005-08-25
  • 打赏
  • 举报
回复
按照你的方法。
#
# mod_gzip 2.0.50
#

LoadModule gzip_module modules/mod_gzip.so

<IfModule mod_gzip.c>
LogFormat "%h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_size}n Ratio:%{mod_gzip_compression_ratio}npct." common_with_mod_gzip_info2
CustomLog logs/gzip.log common_with_mod_gzip_info2
mod_gzip_on Yes
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.htm$
mod_gzip_item_include mime text/.*
mod_gzip_item_exclude file error/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_temp_dir "E:/tmp/gzip"
mod_gzip_command_version mod_gzip_version
mod_gzip_dechunk yes
# mod_gzip_keep_workfiles Yes
</IfModule>

# End of mod_gzip


加上去之后 php页面
<?
phpinfo();
?>
显示不出来,其他可以显示。
谢谢!!!
xdspower 2005-07-14
  • 打赏
  • 举报
回复
支持,学习
fzjw 2005-07-11
  • 打赏
  • 举报
回复
......
fzjw 2005-06-22
  • 打赏
  • 举报
回复
2、mod_perl 2.0.1

安装perl 5.8.7,完成后,在shell中执行:

D:\>ppm install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd

====================
Install 'mod_perl' version 2.0.1 in ActivePerl 5.8.7.813.
====================

Installing D:\server\perl\site\lib\auto\Apache2\typemap
Installing D:\server\perl\site\lib\auto\Apache2\Access\Access.bs
Installing D:\server\perl\site\lib\auto\Apache2\Access\Access.dll
Installing D:\server\perl\site\lib\auto\Apache2\Access\Access.exp
Installing D:\server\perl\site\lib\auto\Apache2\Access\Access.lib
Installing D:\server\perl\site\lib\auto\Apache2\CmdParms\CmdParms.bs
Installing D:\server\perl\site\lib\auto\Apache2\CmdParms\CmdParms.dll
Installing D:\server\perl\site\lib\auto\Apache2\CmdParms\CmdParms.exp
这里省略n多内容......


The Apache2 module mod_perl.so is needed to complete the installation,
and should be placed in your Apache2 modules directory. I will
now fetch and install this for you.

Fetching http://theoryx5.uwinnipeg.ca/ppms/x86/mod_perl.so ... done!
Where should mod_perl.so be placed? [D:/Apache2/modules]D:/apache2/

上面的D:/apache2/为mod_perl.so文件的存储路径,光标会停留在这儿,直到你输入合法路径并回车,然后继续。可以任意设置

mod_perl.so has been successfully installed to D:/apache2.
To enable mod_perl, put in the directives
LoadFile "C:/Path/to/Perl/bin/perl58.dll"
LoadModule perl_module modules/mod_perl.so
in httpd.conf. For more information, visit
http://perl.apache.org/
and especially see
http://perl.apache.org/docs/2.0/rename.html

Successfully installed mod_perl version 2.0.1 in ActivePerl 5.8.7.813.

D:\>

完成后,在D:\apache2下会生成124KB的mod_perl.so文件,就是它了,复制到Apache2的modules目录下,修改httpd.conf

#
# mod_perl 2.0.1
#

LoadFile "D:/perl/bin/perl58.dll"
LoadModule perl_module modules/mod_perl.so

AddHandler perl-script .pl

Alias /perl/ "E:/wwwroot/perl/"
<Location /perl/>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options +ExecCGI
PerlOptions +ParseHeaders
</Location>

# End of mod_perl

写一个测试脚本info.pl(来自官方网站)

[CODE:]

## printenv -- demo CGI program which just prints its environment
##
use strict;
print "Content-type: text/html\n\n";
print "<HTML><BODY><H3>Environment variables</H3><UL>";
foreach (sort keys %ENV) {
my $val = $ENV{$_};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "<LI>$_ = \"${val}\"</LI>\n";
}
#sleep(10);
print "</UL></BODY></HTML>";

通过URL:http://localhost/perl/info.pl访问,可以得到系统的一些信息。
fzjw 2005-06-22
  • 打赏
  • 举报
回复
###############
### 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>

上面是官方网站的配置方法:http://www.schroepl.net/projekte/mod_gzip/index.htm

我自己的配置:

#
# mod_gzip 2.0.50
#

LoadModule gzip_module modules/mod_gzip.so

<IfModule mod_gzip.c>
LogFormat "%h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_size}n Ratio:%{mod_gzip_compression_ratio}npct." common_with_mod_gzip_info2
CustomLog logs/gzip.log common_with_mod_gzip_info2
mod_gzip_on Yes
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.htm$
mod_gzip_item_include mime text/.*
mod_gzip_item_exclude file error/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_temp_dir "E:/tmp/gzip"
mod_gzip_command_version mod_gzip_version
mod_gzip_dechunk yes
# mod_gzip_keep_workfiles Yes
</IfModule>

# End of mod_gzip
fzjw 2005-06-22
  • 打赏
  • 举报
回复
##################
### 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.
# ---------------------------------------------------------------------

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧