Apache 配置文件详解

### Section 1: Global Environment
//当服务器响应主机头(header)信息时显示Apache的版本和操作系统名称
ServerTokens OS
//设置服务器的根目录
ServerRoot "/etc/httpd"

#ScoreBoardFile run/httpd.scoreboard

//设置运行Apache时使用的PidFile的路径
PidFile run/httpd.pid

//若300秒后没有收到或送出任何数据就切断该连接
Timeout 300

//不使用保持连接的功能,即客户一次请求连接只能响应一个文件
/建议用户将此参数的值设置为On,即允许使用保持连接的功能
KeepAlive Off

//在使用保持连接功能时,设置客户一次请求连接能响应文件的最大上限
MaxKeepAliveRequests 100

//在使用保持连接功能时,两个相邻的连接的时间间隔超过15秒,就切断连接
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
##
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
//设置使用Prefork MPM运行方式的参数,此运行方式是Red hat默认的方式


//设置服务器启动时运行的进程数
StartServers     8

//Apache在运行时会根据负载的轻重自动调整空闲子进程的数目
//若存在低于5个空闲子进程,就创建一个新的子进程准备为客户提供服务
MinSpareServers   5

//若存在高于20个空闲子进程,就创建逐一删除子进程来提高系统性能
MaxSpareServers   20

//限制同一时间的连接数不能超过150
MaxClients     150

//限制每个子进程在结束处理请求之前能处理的连接请求为1000
MaxRequestsPerChild 1000


# worker MPM
# StartServers: initial number of server processes to start
//设置使用Worker MPM运行方式的参数

StartServers       2
MaxClients       150
MinSpareThreads   25
MaxSpareThreads   75
ThreadsPerChild   25
MaxRequestsPerChild 0


# perchild MPM
# NumServers: constant number of server processes
//设置使用perchild MPM运行方式的参数

NumServers       5
StartThreads       5
MinSpareThreads     5
MaxSpareThreads   10
MaxThreadsPerChild 20
MaxRequestsPerChild 0


//设置服务器的监听端口
#Listen 12.34.56.78:80
Listen 202.112.85.101:80

#
# Load config files from the config directory "/etc/httpd/conf.d".
//将/etc/httpd/conf.d目录下所有以conf结尾的配置文件包含进来
Include conf.dpublic_html>
#   AllowOverride FileInfo AuthConfig Limit
#   Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
#   
#     Order allow,deny
#     Allow from all
#   

#   
#     Order deny,allow
#     Deny from all
#   

#

//当访问服务器时,依次查找页面Index.html index.htm.var
DirectoryIndex index.html index.html.var

//指定保护目录配置文件的名称
AccessFileName .htaccess

//拒绝访问以.ht开头的文件,即保证.htaccess不被访问

Order allow,deny
Deny from all


//指定负责处理MIME对应格式的配置文件的存放位置
TypesConfig /etc/mime.types
//指定默认的MIME文件类型为纯文本或HTML文件
DefaultType text/plain

//当mod_mime_magic.c模块被加载时,指定magic信息码配置文件的存放位置

#   MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic


//只记录连接Apache服务器的Ip地址,而不纪录主机名
HostnameLookups Off
//指定错误日志存放位置
ErrorLog logs/error_log
//指定记录的错误信息的详细等级为warn等级
LogLevel warn
//定义四中记录日志的格式
LogFormat "%h %l %u %t "%r" %>s %b "%{ Referer }i" "%{ User-Agent }i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{ Referer }i -> %U" referer
LogFormat "%{ User-agent }i" agent

//指定访问日志的纪录格式为combined(混合型),并指定访问日志存放位置
# CustomLog logs/access_log common
CustomLog logs/access_log combined
#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent
#CustomLog logs/access_log combined

//设置apache自己产生的页面中使用apache服务器版本的签名
ServerSignature On

//设置内容协商目录的访问别名
Alias /icons/ "/var/www/icons/"
//设置/var/www/icons/的访问权限

//MultiViews 使用内容协商功决定被发送的网页的性质
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


//设置网页邮件服务
Alias /webmail "/usr/share/squirrelmail"


Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


//设置apache手册的访问别名
Alias /manual "/var/www/manual"


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
//指定DAV加锁数据库文件的存放位置

# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb


Alias /docs   "/home/EMU/webmail/docs/"


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all



# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb


//设置CGI目录的访问别名
scrīptAlias /cgi-bin/ "/var/www/cgi-bin/"

//由于red hat中不使用worker MPM运行方式,所以不加载mod_cgid.c模块

#
# Additional to mod_cgid.c settings, mod_cgid has scrīptsock
# for setting UNIX socket for communicating with cgid.
#
#scrīptsock         logs/cgisock


//设置CGI目录的访问权限

AllowOverride None
Options None
Order allow,deny
Allow from all


//重定向连接
# Redirect permanent /foohttp://www.example.com/bar

//设置自动生成目录列表的显示方式
//FancyIndexing 对每种类型的文件前加上一个小图标以示区别
//VersionSort 对同一个软件的多个版本进行排序
//NameWidth=* 文件名字段自动适应当前目录下的最长文件名
IndexOptions FancyIndexing VersionSort NameWidth=*

//当使用IndexOptions FancyIndexing之后,配置下面的参数
//用于告知服务器在遇到不同的文件类型或扩展名时采用MIME编码格式
//辨别文件类型并显示相应的图标
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

//当使用IndexOptions FancyIndexing之后,配置下面的参数
//用于告知服务器在遇到不同的文件类型或扩展名时采用所指定的格式
//并显示相应的图标
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/scrīpt.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^


//当使用IndexOptions FancyIndexing之后,且无法识别文件类型时
//显示此处定义的图标
DefaultIcon /icons/unknown.gif

#
# AddDescrīption allows you to place a short descrīption after a file in
# server-generated indexes. These are only displayed for FancyIndexed
# directories.
# Format: AddDescrīption "descrīption" filename
#
#AddDescrīption "GZIP compressed document" .gz
#AddDescrīption "tar archive" .tar
#AddDescrīption "GZIP compressed tar archive" .tgz

//当服务器自动列出目录列表时,在所生成的页面之后显示readme.html的内容
ReadmeName README.html
//当服务器自动列出目录列表时,在所生成的页面之前显示header.html的内容
HeaderName HEADER.html

#
# IndexIgnore is a set of filenames which directory indexing should ignore
# and not include in the listing. Shell-style wildcarding is permitted.
#
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

//设置在线浏览用户可以实时解压缩.z   .gz   .tgz类型的文件
//并非所有浏览器都支持
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz


#
# DefaultLanguage nl
# Danish (da) - Dutch (nl) - English (en) - Estonian (et)
# French (fr) - German (de) - Greek-Modern (el)
# Italian (it) - Norwegian (no) - Norwegian Nynorsk (nn) - Korean (kr)
# Portugese (pt) - Luxembourgeois* (ltz)
# Spanish (es) - Swedish (sv) - Catalan (ca) - Czech(cz)
# Polish (pl) - Brazilian Portuguese (pt-br) - Japanese (ja)
# Russian (ru) - Croatian (hr)
#
//设置网页内容的语言种类(浏览器要启用内容协商)
//对中文网页,此项无实际意义
AddLanguage da .dk
AddLanguage nl .nl
AddLanguage en .en
AddLanguage et .et
AddLanguage fr .fr
AddLanguage de .de
AddLanguage he .he
AddLanguage el .el
AddLanguage it .it
AddLanguage ja .ja
AddLanguage pl .po
AddLanguage kr .kr
AddLanguage pt .pt
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pt-br .pt-br
AddLanguage ltz .ltz
AddLanguage ca .ca
AddLanguage es .es
AddLanguage sv .se
AddLanguage cz .cz
AddLanguage ru .ru
AddLanguage tw .tw
AddLanguage zh-tw .tw
AddLanguage hr .hr

//当启用内容协商时,设置语言的先后顺序
LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv tw

//Prefer 当有多种语言可以匹配时,使用LanguagePriority 列表的第一项
//Fallback 当没有语言可以匹配时,使用LanguagePriority 列表的第一项
ForceLanguagePriority Prefer Fallback

//设置默认字符集
AddDefaultCharset ISO-8859-1

//设置各种字符集
AddCharset ISO-8859-1 .iso8859-1 .latin1
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddCharset ISO-8859-3 .iso8859-3 .latin3
AddCharset ISO-8859-4 .iso8859-4 .latin4
AddCharset ISO-8859-5 .iso8859-5 .latin5 .cyr .iso-ru
AddCharset ISO-8859-6 .iso8859-6 .latin6 .arb
AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk
AddCharset ISO-8859-8 .iso8859-8 .latin8 .heb
AddCharset ISO-8859-9 .iso8859-9 .latin9 .trk
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5     .Big5     .big5
# For russian, more than one charset is used (depends on client, mostly):
AddCharset WINDOWS-1251 .cp-1251   .win-1251
AddCharset CP866     .cp866
AddCharset KOI8-r     .koi8-r .koi8-ru
AddCharset KOI8-ru   .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-8     .utf8

# The set below does not map to a specific (iso) standard
# but works on a fairly wide range of browsers. Note that
# capitalization actually matters (it should not, but it
# does for some browsers).
#
# Seeftp://ftp.isi.edu/in-notes/iana/assignments/character-sets
# for a list of sorts. But browsers support few.
#
AddCharset GB2312     .gb2312 .gb
AddCharset utf-7     .utf7
AddCharset utf-8     .utf8
AddCharset big5     .big5 .b5
AddCharset EUC-TW     .euc-tw
AddCharset EUC-JP     .euc-jp
AddCharset EUC-KR     .euc-kr
AddCharset shift_jis   .sjis

//添加新的MIME类型(避免用户编辑/etc/mime.types)
AddType application/x-tar .tgz


#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scrīpts outside of scrīptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-scrīpt .cgi

#
# For files that include their own HTTP headers:
#
#AddHandler send-as-is asis

//设置apcche对某些扩展名的处理方式
AddHandler imap-file map
AddHandler type-map var

//使用过滤器执行SSI
AddOutputFilter INCLUDES .shtml

//设置错误页面目录的别名
Alias /error/ "/var/www/error/"




AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback

//设置错误输出页面
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var


//设置浏览器匹配
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4.0" force-response-1.0
BrowserMatch "Java/1.0" force-response-1.0
BrowserMatch "JDK/1.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully

#
# Allow server status reports, with the URL of http://servername/server-status
# Change the ".your-domain.com" to match your domain to enable.
#
#
#   SetHandler server-status
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".your-domain.com" to match your domain to enable.
#
#
#   SetHandler server-info
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


//设置APache为代理服务器
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#
#ProxyRequests On
#
#
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


#
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#
#ProxyVia On

#
# To enable the cache as well, edit and uncomment the following lines:
# (no cacheing without CacheRoot)
#
#CacheRoot "/etc/httpd/proxy"
#CacheSize 5
#CacheGcInterval 4
#CacheMaxExpire 24
#CacheLastModifiedFactor 0.1
#CacheDefaultExpire 1
#NoCache a-domain.com another-domain.edu joes.garage-sale.com

#

# End of proxy directives.

//设置虚拟主机
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
#
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
//指令监听本地计算机上所有的IP地址请求
#NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
//定义虚拟主机的设置,此设置将覆盖前面有的的相同指令
#   ServerAdmin webmaster at dummy-host dot example.com
#   DocumentRoot /www/docs/dummy-host.example.com
#   ServerName dummy-host.example.com
#   ErrorLog logs/dummy-host.example.com-error_log
#   CustomLog logs/dummy-host.example.com-access_log common
#
//设置浏览器匹配
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4.0" force-response-1.0
BrowserMatch "Java/1.0" force-response-1.0
BrowserMatch "JDK/1.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully

#
# Allow server status reports, with the URL of http://servername/server-status
# Change the ".your-domain.com" to match your domain to enable.
#
#
#   SetHandler server-status
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".your-domain.com" to match your domain to enable.
#
#
#   SetHandler server-info
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


//设置APache为代理服务器
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#
#ProxyRequests On
#
#
#   Order deny,allow
#   Deny from all
#   Allow from .your-domain.com
#


#
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#
#ProxyVia On

#
# To enable the cache as well, edit and uncomment the following lines:
# (no cacheing without CacheRoot)
#
#CacheRoot "/etc/httpd/proxy"
#CacheSize 5
#CacheGcInterval 4
#CacheMaxExpire 24
#CacheLastModifiedFactor 0.1
#CacheDefaultExpire 1
#NoCache a-domain.com another-domain.edu joes.garage-sale.com

#

# End of proxy directives.

//设置虚拟主机
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
#
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
//指令监听本地计算机上所有的IP地址请求
#NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
//定义虚拟主机的设置,此设置将覆盖前面有的的相同指令
#   ServerAdmin webmaster at dummy-host dot example.com
#   DocumentRoot /www/docs/dummy-host.example.com
#   ServerName dummy-host.example.com
#   ErrorLog logs/dummy-host.example.com-error_log
#   CustomLog logs/dummy-host.example.com-access_log common
#

你可能感兴趣的:(apache)