首页 > 代码库 > httpd配置文件详解(v2.2)

httpd配置文件详解(v2.2)

#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They‘re here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the ‘global environment‘).
#  2. Directives that define the parameters of the ‘main‘ or ‘default‘ server,
#     which responds to requests that aren‘t handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server‘s control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/etc/httpd" will be interpreted by the
# server as "/etc/httpd/logs/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# Don‘t give away too much information about all the subcomponents
# we are running.  Comment out this line if you don‘t mind remote sites
# finding out what major optional modules you are running
ServerTokens OS		#该参数设置http头部返回的apache版本信息,可用的值和含义如下:
							#Prod:仅软件名称,例如:apache 
							#Major:包括主版本号,例如:apache/2 
							#Minor:包括次版本号,例如:apache/2.0 
							#Min:仅apache的完整版本号,例如:apache/ 2.0.54 
							#OS:包括操作系统类型,例如:apache/2.0.54(Unix) 
							#Full:包括apache支持的模块及模块版本号,例如:Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7g

#
# ServerRoot: The top of the directory tree under which the server‘s
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation
# (available at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/httpd"		#服务器根目录:apache软件配置文件、error_log错误日志文件、访问日志access_log等存放位置。ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是相对路径,那么真实路径就位于这个ServerR oot定义的路径之下。 

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
#
PidFile run/httpd.pid		#第一个httpd进程(所有其他进程的父进程)的进程号。PidFile指定的文件将记录httpd守护进程的进程号,由于httpd能自动复制其自身,因此系统中有多个httpd进程,但只有一个进程为最初启动的进程,它为其他进程的父进程,对这个进程发送信号将影响所有的httpd进程。PidFILE定义的文件中就记录httpd父进程的进程号。 


#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 120			#接送和发送资源超时时间,超时后断开连接。Timeout定义客户程序和服务器连接的超时间隔,超过这个时间间隔(秒)后服务器将断开与客户机的连接。 


#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On		#是否开启保持会话连接功能,即当客户端连接到服务器时,下载完数据后仍然保持连接状态。开启后可避免同一用户请求资源时重复进行TCP三次握手四次断开,提高服务器效能.
					#在HTTP 1.0中,一次连接只能作传输一次HTTP请求,而KeepAlive参数用于支持HTTP 1.1版本的一次连接、多次传输功能,这样就可以在一次连接中传递多个HTTP请求。虽然只有较新的浏览器才支持这个功能,但还是打开使用这个选项。 

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100	#保持连接过程中的允许的最大请求数,超过此数量后断开连接;0表示无限制
    					#MaxKeepAliveRequests为一次连接可以进行的HTTP请求的最大请求次数。将其值设为0将支持在一次连接内进行无限次的传输请求。事实上没有客户程序在一次连接中请求太多的页面,通常达不到这个上限就完成连接了。 

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15		#保持连接的超时时间(同一次连接中,等待同一客户端下一次请求的超时时间,单位秒)
						#KeepAliveTimeout测试一次连接中的多次请求传输之间的间隔时间,如果服务器已经完成了一次请求,但一直没有接收到客户程序的下一次请求,在间隔超过了这个参数设置的值之后,服务器就断开连接。 

##
## Server-Pool Size Regulation (MPM specific)
## 

# prefork MPM (MPM:多道处理模块;prefork:预先生成,基于prefork,内核会为每一个用户请求分配一个进程,性能较低,但是最稳定可靠,依赖于prefork.c模块)
# 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
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       8	#(程序开启时默认开启的服务进程数量)
MinSpareServers    5	#最小的空闲服务器数量(服务进程数量),保持这些空闲的服务器以能够及时接受客户端的请求
MaxSpareServers   20	#最大的空闲服务器数量,当断开连接的服务进程成为空闲进程后数量超过20个后,关闭多余的空闲服务器进程。
ServerLimit      256	#允许响应请求的服务器最大进程数,也就是同时提供服务的服务器进程数量
MaxClients       256	#响应用户会话的最大进程的数量,允许连接的最大的客户端数量,不得大于ServerLimit
MaxRequestsPerChild  4000	#每个进程生存期处理的最大请求数量,超过后关闭此进程		解析:使用子进程的方式提供服务的Web服务,常用的方式是一个子进程为一次连接服务,这样造成的问题就是每次连接都需要生成、退出子进程的系统操作,使得这些额外的处理过程占据了计算机的大量处理能力。因此最好的方式是一个子进程可以为多次连接请求服务,这样就不需要这些生成、退出进程的系统消耗,Apache就采用了这样的方式,一次连接结束后,子进程并不退出,而是停留在系统中等待下一次服务请求,这样就极大的提高了性能。 但由于在处理过程中子进程要不断的申请和释放内存,次数多了就会造成一些内存垃圾,就会影响系统的稳定性,并且影响系统资源的有效利用。因此在一个副本处理过一定次数的请求之后,就可以让这个子进程副本退出,再从原始的httpd进程中重新复制一个干净的副本,这样就能提高系统的稳定性。这样,每个子进程处理服务请求次数由MaxRequestPerChild定义。 缺省的设置值为30,这个值对于具备高稳定性特点的FreeBSD系统来讲是过于保守的设置,可以设置为1000甚至更高,设置为0支持每个副本进行无限次的服务处理。 

</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers         2		#启动apache时启动的httpd进程个数。
MaxClients         150		#最大并发连接数
MinSpareThreads     25		#最小的空闲工作线程数量
MaxSpareThreads     75 		#最大的空闲工作线程数量
ThreadsPerChild     25		#每个进程生成多少个线程
MaxRequestsPerChild  0		#每个子进程被请求服务多少次后被kill掉。0表示不限制
</IfModule>

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80	#服务监听套接字,默认为监听服务器所有网卡的80端口,可重复指定多次
Listen 80				#表示监听所有地址的80端口

#
# Dynamic Shared Object Support(DSO,动态共享对象) 
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule‘ lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l‘) do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#加载模块:格式为:LoadModule 模块名 模块路径

LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so

#
# The following modules are not loaded by default:
#
#LoadModule cern_meta_module modules/mod_cern_meta.so
#LoadModule asis_module modules/mod_asis.so

#
# Load config files from the config directory "/etc/httpd/conf.d".
#
Include conf.d/*.conf	#加载其他的配置文件

#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
#ExtendedStatus On		#Apache服务器可以通过特殊的HTTP请求,来报告自身的运行状态,打开这个ExtendedStatus 参数可以让服务器报告更全面的运行状态信息,设为OFF时,只提供基本的运行状态信息
		
		 <Location /server-status>			#通过"server-status" handler的调用,实现查看服务器的运行状态信息;<Location>提供了基于URL的访问控制,此例中输入http://192.168.0.30/server-status即可访问查看服务器的运行状态信息
			  SetHandler server-status
			  AuthType Basic				#因服务器的运行状态信息属于私密信息,不能所有的人查看,所以对该URL的访问进行基本的认证访问控制。
			  AuthName "Sever Status"
			  AuthUserFile "/etc/httpd/conf/.htpasswd"
			  Require valid-user
			  Order deny,allow
			  Allow from all
		 </Location>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
#  . On SCO (ODT 3) use "User nouser" and "Group nogroup".
#  . On HPUX you may not be able to use shared memory as nobody, and the
#    suggested workaround is to create a user www and use that user.
#  NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
#  when the value of (unsigned)Group is above 60000; 
#  don‘t use Group #-1 on these systems!
#
User apache		#允许运行httpd的用户
Group apache	#允许运行httpd的组


### Section 2: ‘Main‘ server configuration
#
# The directives in this section set up the values used by the ‘main‘
# server, which responds to any requests that aren‘t handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin root@localhost	# 服务管理员邮箱,当服务发生错误是会电邮至此邮箱。可以在每一个虚拟主机中配置。
							#配置文件中应该改变的也许只有ServerAdmin, 这一项用于配置WWW服务器的管理员的email地址,这将在HTTP服务出现错误的条件下返回给浏览器,以便让Web使用者和管理员联系,报告错误。习惯上使用服务器上的webmaster作为WWW服务器的管理员,通过邮件服务器的别名机制,将发送到webmaster 的电子邮件发送给真正的Web管理员。 

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn‘t have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make 
# redirections work in a sensible way.
#
#ServerName www.example.com:80	#服务器的主机名。如果不指定,启动服务时,会根据ip反解并自动设定主机名。在基于主机的虚拟主机,使用此指令来限制主机名
								#缺省情况下,并不需要指定这个ServerName参数,服务器将自动通过名字解析过程来获得自己的名字,但如果服务器的名字解析有问题(通常为反向解析不正确),或者没有正式的DNS名字,也可以在这里指定IP地址。当ServerName设置不正确的时候,服务器不能正常启动。 
    						#通常一个Web服务器可以具有多个名字,客户浏览器可以使用所有这些名字或IP地址来访问这台服务器,但在没有定义虚拟主机的情况下,服务器总是以自己的正式名字回应浏览器。ServerName就定义了Web服务器自己承认的正式名字,例如一台服务器名字(在DNS中定义了A类型)为freebsd.exmaple.org.cn,同时为了方便记忆还定义了一个别名(CNAME记录)为www.exmaple.org.cn,那么Apache自动解析得到的名字就为freebsd.example.org.cn,这样不管客户浏览器使用哪个名字发送请求,服务器总是告诉客户程序自己为freebsd.example.org.cn。虽然这一般并不会造成什么问题,但是考虑到某一天服务器可能迁移到其他计算机上,而只想通过更改DNS中的www别名配置就完成迁移任务,所以不想让客户在其书签中使用 freebsd记录下这个服务器的地址,就必须使用ServerName来重新指定服务器的正式名字。 

#
# UseCanonicalName: Determines how Apache constructs self-referencing 
# URLs and the SERVER_NAME and SERVER_PORT variables.限定了Apache如何建立自引用URLs。。。等变量。
# When set "Off", Apache will use the Hostname and Port supplied
# by the client.  When set "On", Apache will use the value of the
# ServerName directive.
#
UseCanonicalName Off	#不使用别名,使用客户端提供的主机名和端口。

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"	#文档根目录:指定apache服务器网页(文档)根目录,URL中主机后的路径就是相对于此路径而言的(例如http://192.168.0.30/bbs/images/logo.gif相当于本地路径/var/www/html/bbs/images/logo.gif),默认为/var/www/html,提供的web文档来源于这个文件夹。修改此项后,需要设定此目录的访问权限
								#DocumentRoot定义这个服务器对外发布的超文本文档存放的路径,客户程序请求的URL就被映射为这个目录下的网页文件。这个目录下的子目录,以及使用符号连接指出的文件和目录都能被浏览器访问,只是要在URL上使用同样的相对目录名。 
								#注意,符号连接虽然逻辑上位于根文档目录之下,但实际上可以位于计算机上的任意目录中,因此可以使客户程序能访问那些根文档目录之外的目录,这在增加了灵活性的同时但减少了安全性。Apache在目录的访问控制中提供了FollowSymLinks选项来打开或关闭支持符号连接的特性。 

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />	#目录容器containter,这个目录容器是关于/的,所有设置是针对于/的
    Options FollowSymLinks
    AllowOverride None
</Directory>
		#Apache服务器可以针对目录进行文档的访问控制,然而访问控制可以通过两种方式来实现,一个是在设置文件httpd.conf(或access.conf)中针对每个目录进行设置,另一个方法是在每个目录下设置访问控制文件,通常访问控制文件名字为.htaccess。虽然使用这两个方式都能用于控制浏览器的访问,然而使用配置文件的方法要求每次改动后重新启动httpd守护进程,比较不灵活,因此主要用于配置服务器系统的整体安全控制策略,而使用每个目录下的.htaccess文件设置具体目录的访问控制更为灵活方便。 
		#Directory语句就是用来定义目录的访问限制的,这里可以看出它的标准语法,为一个目录定义访问限制。上例的这个设置是针对系统的根目录进行的,设置了允许符号连接的选项FollowSymLinks ,以及使用AllowOverride None表示不允许这个目录下的访问控制文件来改变这里进行的配置,这也意味着不用查看这个目录下的相应访问控制文件。 
		#由于Apache对一个目录的访问控制设置是能够被下一级目录继承的,因此对根目录的设置将影响到它的下级目录。注意由于AllowOverride None的设置,使得Apache服务器不需要查看根目录下的访问控制文件,也不需要查看以下各级目录下的访问控制文件,直至httpd.conf(或access.conf )中为某个目录指定了允许Alloworride,即允许查看访问控制文件。由于Apache对目录访问控制是采用的继承方式,如果从根目录就允许查看访问控制文件,那么Apache就必须一级一级的查看访问控制文件,对系统性能会造成影响。而缺省关闭了根目录的这个特性,就使得Apache从httpd.conf中具体指定的目录向下搜寻,减少了搜寻的级数,增加了系统性能。因此对于系统根目录设置AllowOverride None不但对于系统安全有帮助,也有益于系统性能。 

# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something‘s not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn‘t give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

# 站点路径访问控制:
#           Directory:基于本地文件系统路径做访问控制
#           Location:基于URL访问路径做访问控制
#           Options:可以在选项后加“-”关闭此功能
#               Indexes:索引目录:当访问的路径下无默认的主页面,将该目录下所有资源以列表的形式呈现给用户,非常危险,不建议开启
#               FollowSymLinks:支持符号链接访问原始文件资源(通过符号连接访问原文件),可能会降低服务器速度,不建议开启,但这可以使浏览器能够访问文档根目录(DocumentRoot)之外的文档 
#				None:表示不允许这个目录下的访问控制文件来改变目录容器里进行的配置,这也意味着不用查看这个目录下的相应访问控制文件。 
#				All:所有选项的都启用
#				Includes:包含:允许使用mod_include模块实现服务器端包含(SSI:Sever-Side Includes)
#				SymLinksifOwnerMatch:在符号链接文件属主属组与原始文件的属主属组相同时,允许跟随符号连接所指向的原始文件
#				ExecCGI:允许使用mod_cgi模块执行该目录中的CGI脚本
#				MultiViews:允许使用mod_negotiation实现内容协商(例如协商不同语言显示页面)
#
# AllowOverride controls what directives may be placed in .htaccess files.#确定允许存在于.htaccess文件中的指令类型;当服务器发现一个.htaccess文件(由AccessFileName指定)时,它需要知道在这个文件中声明的哪些指令能覆盖在此之前指定的配置指令。AllowOverride仅在不包含正则表达式的<Directory>配置段中才是有效的。在<Location>, <DirectoryMatch>, <Files>配置段中都是无效的。
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit

    AllowOverride None
	
#
# Controls who can get stuff from this server.
#
    Order allow,deny	#匹配的规则:最终匹配:先通过allow和deny进行匹配,如果只匹配到一个(allow或者deny),则以匹配到的为准;如果都匹配或都不匹配时以默认为准(后者)。
    Allow from all
	Deny from 192.168.0.100

</Directory>
	#这里定义的是系统对外发布文档的目录“/var/www/html”的访问设置,设置不同的AllowOverride选项,以定义配置文件中的目录设置和用户目录下的安全控制文件的关系,而Options选项用于定义该目录的特性。 
	#配置文件和每个目录下的访问控制文件都可以设置访问限制,配置文件是由管理员设置的,而每个目录下的访问控制文件是由目录的属主设置的,因此管理员可以规定目录的属主是否能覆盖系统在配置文件中的配置,这就需要使用 AllowOverride参数进行设置,通常可以设置的值为: 
	#AllowOverride的设置 对每个目录访问控制文件作用的影响如下:  
		#All 缺省值,使访问控制文件可以覆盖系统配置  
		#None 服务器忽略访问控制文件的设置  
		#Options 允许访问控制文件中可以使用Options参数定义目录的选项 (就是可以使用访问控制文件中的Options参数来覆盖系统配置?)
		#FileInfo 允许访问控制文件中可以使用AddType等参数设置来控制文档类型
		#AuthConfig 允许访问控制文件使用AuthName,AuthType等针对每个用户的认证授权机制,这使目录属主能用口令和用户名来保护目录  
		#Limit 允许对访问目录的客户机的IP地址和名字进行限制,包括Allow Deny和Order。上例中使用的Order、Allow、Deny等参数,是Limit语句中用来根据浏览器的域名和IP地址来控制访问的一种方式。其中Order定义处理Allow和Deny的顺序,而Allow、Deny则针对名字或IP进行访问控制设置,上例使用allow from all,表示允许所有的客户机访问这个目录,而不进行任何限制。 
   
	#每个目录具备一定属性,可以使用Options来控制这个目录下的一些访问特性设置,以下为常用的特性选项: 
	#Options设置
		#All 所有的目录特性都有效,这是缺省状态  
		#None 所有的目录特性都无效  
		#FollowSymLinks 允许使用符号连接访问原始文件资源(通过符号连接访问原文件),可能会降低服务器速度,不建议开启,这将使浏览器有可能访问文档根目录(DocumentRoot)之外的文档  
		#Indexes 索引目录:允许浏览器可以生成这个目录下所有文件的索引,使得在这个目录下没有index.html(或其他索引文件)时,能向浏览器发送这个目录下的文件列表 ,非常危险,不建议开启 
		#SymLinksIfOwnerMatch 只有符号链接文件属主与原始文件的属主相同时,才允许访问符号连接所指向的原始文件,这个设置将增加一些安全性  
		#ExecCGI 允许这个目录下可以执行CGI程序(使用mod_cgi模块)
		#Includes:包含:允许使用mod_include模块实现服务器端包含(SSI:Sever-Side Includes)
		#MultiViews:允许使用mod_negotiation实现内容协商(例如协商不同语言显示页面)

<Directory "/var/www/htdocs">
AllowOverride AuthConfig	#使用认证配置访问该目录
		
AuthType Basic 		#认证类型:基本认证。此指令选择了一个目录的用户认证类型。目前只实现了Basic基本认证(mod_auth_basic)和Digest摘要认证(mod_auth_digest)。
AuthName "Restricted Files" 	#此指令为目录的授权域设置名字来作为提示信息。此域将发送给客户端以使用户了解应当发送哪个用户名和密码。提供给AuthName的字符串将出现在大多数浏览器提供的密码对话框中。

AuthUserFile /etc/http/conf/.htpasswd	#设定一个含有认证使用的用户名/密码列表的纯文本文件。使用命令行工具htpasswd可以用来创建/维护仅用于HTTP基本认证的密码文件,示例:htpasswd -c -m /etc/http/conf/.htpasswd tom 注意:-c 创建密码文件,创建第一个用户时使用;第二次使用时,不要使用-c,否则会重新创建文件覆盖原文件,此外-D删除用户
#Require user ljzsdut	#指定ljzsdut用户可以访问此目录。其他参数有valid-user表示AuthUserFile所指定文件中所有的有效用户都可以访问此目录。

AuthGroupFile /web/groups		#设定一个包含用于执行用户认证的用户组列表的纯文本文件()。这个用户组列表文件每行包含一个用户组名称,后跟一个冒号,再跟该组用户的用户名称,用户名之间以空格分隔。示例:mygroup: bob joe anne	
Require group admin		#只有隶属于admin组的用户可以访问此目录。
</Directory>

#
# UserDir: The name of the directory that is appended onto a user‘s home
# directory if a ~user request is received.
#
# The path to the end user account ‘public_html‘ directory must be
# accessible to the webserver userid.  This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>	#用户目录,基于mod_userdir.so实现让每个用户在自己的家目录创建自己的个人站点,访问地址:ttp://Server_IP/~Username/
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir disable		#禁用用户目录

    #
    # To enable requests to /~user/ to serve the user‘s public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    # 
    #UserDir public_html		#设定用户目录,注意让此目录具有o+x权限,其他组才有访问权限
								#当在一台FreeBSD上运行Apache服务器时,这台计算机上的所有用户都可以有自己的网页路径,形如 http://freebsd.example.org.cn/~user,使用波浪符号加上用户名就可以映射到用户自己的网页目录上。映射目录为用户个人主目录下的一个子目录,其名字就用UseDir这个参数进行定义,缺省为public_html。如果不想为正式的用户提供网页服务,使用DISABLED作UserDir的参数即可。 

</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
#<Directory /home/*/public_html>		#这里可以看到Directory的另一个用法,即可以通过简单的模式匹配方法,针对分布在不同目录下的子目录定义访问控制权限。这样设置就需要Apache服务器对每个路径进行额外的处理,因此就会降低服务器的性能,所以缺省情况并没有打开这种访问限制。 
#    AllowOverride FileInfo AuthConfig Limit
#    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
#    <Limit GET POST OPTIONS>	#限制所有用户允许使用GET POST OPTIONS方法。这里的Limit语句就是用来针对具体的请求方法来设定访问控制的,其中可以使用GET、POST等各种服务器支持的请求方法做Limit的参数,来设定对不同请求方法的访问限制。一般可以打开对GET、POST、HEAD三种请求方法,而屏蔽其他的请求方法,以增加安全性。Limit语句中,可以使用Order 、Allow、Deny,Allow和Deny中可以使用匹配的方法针对域名和IP进行限制,只是对于域名是从后向前匹配,对于IP地址则从前向后匹配。 
#        Order allow,deny
#        Allow from all
#    </Limit>
#    <LimitExcept GET POST OPTIONS>		#限制所有用户拒绝使用除GET POST OPTIONS之外方法
#        Order deny,allow
#        Deny from all
#    </LimitExcept>
#</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the 
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var	#定义某个目录的默认的主页(当访问路径为目录时就访问此主页),优先级由左到右。作用是我打开网站时,输入 域名或者url/目录/,如果目录下存在DirectoryIndex设置的文件名的文档如index.html index.html.var等,默认就打开这样的文件。没有这些文档的话,打开存在的目录会显示Forbidden错误或在启用Options Indexes前提下,显示目录内文件的索引
											#很多情况下,URL中并没有指定文档的名字,而只是给出了一个目录名。那么Apache服务器就自动返回这个目录下由DirectoryIndex定义的文件,当然可以指定多个文件名字,系统会这个目录下顺序搜索。当所有由DirectoryIndex指定的文件都不存在时,Apache服务器可以根据系统设置,生成这个目录下的所有文件列表,提供用户选择。此时该目录的访问控制选项中的Indexes选项(Options Indexes )必须打开,以使得服务器能够生成目录列表,否则Apache将拒绝访问。 

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess	#设定每个目录的访问控制机制的文件名称(此文件会降低apache的执行效率)
							#AccessFileName定义每个目录下的访问控制文件的文件名,缺省为.htaccess ,可以通过更改这个文件,来改变不同目录的访问控制限制。 
#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ~ "^\.ht">	#<Files>指令提供了基于文件名的访问控制;~表示开启正则匹配,否则参数应当是一个文件名或是一个包含通配符的字符串
    Order allow,deny
    Deny from all
</Files>			#实现拒绝所有人访问.ht开头的文件
			#除了可以针对目录进行访问控制之外,还可以根据文件来设置访问控制,这就是File语句的任务。使用File 语句,不管文件处于哪个目录,只要名字匹配,就必须接受相应的访问控制。这个语句对于系统安全比较重要,例如上例将屏蔽所有的使用者不能访问.htaccess文件,这样就避免.htaccess中的关键安全信息不至于被客户获取。 

#
# TypesConfig describes where the mime.types file (or equivalent) is
# to be found.
#
TypesConfig /etc/mime.types		#MIME type的配置文件
								#TypeConfig用于设置保存有不同的MIME类型数据的文件名,在FreeBSD下缺省设置为/usr/local/etc/apache/mime.types。
#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain		#默认的MIME类型。
							#如果Web服务器不能决定一个文档的缺省类型,这通常表示文档使用了非标准的后缀,那么服务器就使用 DefaultType定义的MIME类型将文档发送给客户浏览器。这里的设置为text/plain,这样设置的问题是,如果服务器不能判断出文档的MIME,那么大部分情况下这个文档为一个二进制文档,但使用 text/plain格式发送回去,浏览器将在内部打开它而不会提示保存。因此建议将这个设置更改为 application/octet-stream,这样浏览器将提示用户进行保存。 
#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
<IfModule mod_mime_magic.c>
#   MIMEMagicFile /usr/share/magic.mime
    MIMEMagicFile conf/magic
</IfModule>
	#除了从文件的后缀出发来判断文件的MIME类型之外,Apache还可以进一步分析文件的一些特征,来判断文件的真实MIME类型。这个功能是由mod_mime_magic模块实现的,它需要一个记录各种MIME类型特征的文件,以进行分析判断。上面的设置是一个条件语句,如果载入了这个模块,就必须指定相应的标志文件magic的位置。  

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it‘d be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off			#通常连接时,服务器仅仅可以得到客户机的IP地址,如果要想获得客户机的主机名,以进行日志记录和提供给 CGI程序使用,就需要使用这个HostnameLookups选项,将其设置为On打开DNS反查功能。但是这将使服务器对每次客户请求都进行DNS查询,增加了系统开销,使得反应变慢,因此缺省设置为使用Off关闭此选项。关闭选项之后,服务器就不会获得客户机的主机名,而只能使用IP地址来记录客户。 


#
# EnableMMAP: Control whether memory-mapping is used to deliver
# files (assuming that the underlying OS supports it).
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  On some systems, turning it off (regardless of
# filesystem) can improve performance; for details, please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablemmap
#
#EnableMMAP off

#
# EnableSendfile: Control whether the sendfile kernel support is 
# used to deliver files (assuming that the OS supports it). 
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
#EnableSendfile off

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host‘s errors will be logged there and not here.
#
ErrorLog logs/error_log		#错误日志的位置


#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn		#日志级别
					#这里定义了系统日志的形式,对于服务器错误记录, 由ErrorLog、LogLevel 来定义不同的错误日志文件及其记录内容。  
   
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined	#定义combined日志格式
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

		#LogFormat是用于定义不同类型的日志进行记录时使用的格式, 这里使用了以%开头的宏定义,以记录不同的内容。
			#%h :Remote host	远程主机IP
			#%l :Remote logname	远程登录名
			#%u :Remote user (from auth)	远程用户(来自于网页的认证用户)
			#%t :Time the request was received		收到请求报文的时间
			#%r : First line of request(请求报文的起始行:”方法+URL+协议版本号“
			#%s:Status;%>s:the last Status	状态码
			#%b :Size of response in bytes		相应报文的大小,单位:bytes
			#%{Referer}i :页面来源
			#%{User-Agent}i :用户(代理)客户端(浏览器)

# "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this
# requires the mod_logio module to be loaded.
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here.  Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common

#
# If you would like to have separate agent and referer logfiles, uncomment
# the following directives.
#
#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/access_log combined		#定义访问日志的位置
	#对于系统的访问日志,缺省使用CustomLog参数定义日志的位置,缺省使用combined 参数指定将所有的访问日志放在一个文件中,然而也可以将不同种类的访问日志放在不同的日志记录文件中,这是通过在 CustomLog中指定不同的记录类型来完成的。common表示普通的对单页面请求访问记录,referer表示每个页面的引用记录,可以看出一个页面中包含的请求数,agent表示对客户机的类型记录,显然可以将现有的combined 定义的设置行注释掉,并使用common、referer和agent作为CustomLog的参数,来为不同种类的日志分别指定日志记录文件。 
	#如果这些参数指定的文件使用的是相对路径,那么就是相对于ServerRoot的路径。 
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature On		#在页面产生错误时是否出现服务器版本信息。推荐设置为Off 
						#一些情况下,例如当客户请求的网页并不存在时,服务器将产生错误文档,缺省情况下由于打开了 ServerSignature选项,错误文档的最后一行将包含服务器的名字、Apache的版本等信息。有的管理员更倾向于不对外显示这些信息,就可以将这个参数设置为Off,或者设置为Email,最后一行将替换为对ServerAdmin 的Email提示。 

#
# Aliases: Add here as many aliases as you need (with no limit). The format is 
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL.  So "/icons" isn‘t aliased in this
# example, only "/icons/".  If the fakename is slash-terminated, then the 
# realname must also be slash terminated, and if the fakename omits the 
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings.  If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/var/www/icons/"		#路径别名,将/icons/映射到"/var/www/icons/"	。实现访问文档根目录以外的路径
									#Alias参数用于将URL与服务器文件系统中的真实位置进行直接映射,一般的文档将在DocumentRoot 中进行查询,然而使用Alias定义的路径将直接映射到相应目录下,而不再到DocumentRoot 下面进行查询。因此Alias可以用来映射一些公用文件的路径,例如保存了各种常用图标的icons路径。这样使得除了使用符号连接之外,文档根目录(DocumentRoot)外的目录也可以通过使用了Alias映射,提供给浏览器访问。 
									#定义好映射的路径之后,应该需要使用Directory语句设置访问限制。 
<Directory "/var/www/icons">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

#
# WebDAV module configuration section.
# 
<IfModule mod_dav_fs.c>
    # Location of the WebDAV lock database.
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
	#ScriptAlias也是用于URL路径的映射,但与Alias的不同在于,ScriptAlias是用于映射CGI程序的路径,这个路径下的文件都被定义为CGI程序,通过执行它们来获得结果,而非由服务器直接返回其内容。缺省情况下CGI程序使用cgi-bin目录作为虚拟路径。 

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

#
# Redirect allows you to tell clients about documents which used to exist in
# your server‘s namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# Example:
# Redirect permanent /foo http://www.example.com/bar	#Redirect参数是用来重写URL的,当浏览器访问服务器上的一个已经不存在的资源的时候,服务器返回给浏览器新的URL,告诉浏览器从该URL中获取资源。这主要用于原来存在于服务器上的文档,改变了位置之后,而又希望能使用老URL能访问到,以保持与以前的URL兼容。  

#
# Directives controlling the display of server-generated directory listings.
#

#
# IndexOptions: Controls the appearance of server-generated directory
# listings.
#
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

#
# AddIcon* directives tell the server which icon to show for different
# files or filename extensions.  These are only displayed for
# FancyIndexed directories.
#
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/*

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/script.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^^

#
# DefaultIcon is which icon to show for files which do not have an icon
# explicitly set.
#
DefaultIcon /icons/unknown.gif

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

#
# ReadmeName is the name of the README file the server will look for by
# default, and append to directory listings.
#
# HeaderName is the name of a file which should be prepended to
# directory indexes. 
ReadmeName README.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
		#当一个HTTP请求的URL为一个目录的时候,服务器返回这个目录中的索引文件。但如果一个目录中不存在缺省的索引文件,并且该服务器又许可显示目录文件列表的时候,就会显示出这个目录中的文件列表,为了使得这个文件列表能具有可理解性,而不仅仅是一个简单的列表,就需要前面的这些设置参数。 
		#如果使用了IndexOptions FancyIndexing选项,可以让服务器产生的目录列表中针对各种不同类型的文档引用各种图标。而哪种文件使用哪种图标,则使用下面的 AddIconByEncoding、AddIconByType以及AddIcon来定义,分别依据MIME的编码、类型以及文件的后缀来判断使用何种图标。如果不能确定文档使用的图标,就使用 DefaultIcon定义的缺省图标。 
		#同样,使用AddDescription可以为不同类型的文档加入不同的描述。并且,服务器还在目录下,查询使用ReadmeName和HeaderName定义的文件(自动加上. html后缀,如果没有发现,再使用.txt后缀进行搜索),如果发现了这些文件,就在文件列表之前首先显示这些文件的内容,以使得普通目录列表具备更大的可理解性。 
		#IndexIgnore让服务器在列出文件列表时忽略相应的文件, 这里使用模式配置的方式定义文件名。 

#
# DefaultLanguage and AddLanguage allows you to specify the language of 
# a document. You can then use content negotiation to give a browser a 
# file in a language the user can understand.
#
# Specify a default language. This means that all data
# going out without a specific language tag (see below) will 
# be marked with this one. You probably do NOT want to set
# this unless you are sure it is correct for all cases.
#
# * It is generally better to not mark a page as 
# * being a certain language than marking it with the wrong
# * language!
#
# DefaultLanguage nl
#
# Note 1: The suffix does not have to be the same as the language
# keyword --- those with documents in Polish (whose net-standard
# language code is pl) may wish to use "AddLanguage pl .po" to
# avoid the ambiguity with the common suffix for perl scripts.
#
# Note 2: The example entries below illustrate that in some cases 
# the two character ‘Language‘ abbreviation is not identical to 
# the two character ‘Country‘ code for its country,
# E.g. ‘Danmark/dk‘ versus ‘Danish/da‘.
#
# Note 3: In the case of ‘ltz‘ we violate the RFC by using a three char
# specifier. There is ‘work in progress‘ to fix this and get
# the reference data for rfc1766 cleaned up.
#
# Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl)
# English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de)
# Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja)
# Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn)
# Norwegian (no) - Polish (pl) - Portugese (pt)
# Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv)
# Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW)
#
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

#
# LanguagePriority allows you to give precedence to some languages
# in case of a tie during content negotiation.
#
# Just list the languages in decreasing order of preference. We have
# more or less alphabetized them here. You probably want to change this.
#
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
		#一个HTML文档可以同时具备多个语言的版本,如对于file1.html文档可以具备file1.html.en、file1.html.fr 等不同的版本,每个语言后缀必须使用AddLanguage进行定义。这样服务器可以针对不同国家的客户,通过与浏览器进行协商,发送不同的语言版本。而LanguagePriority 定义不同语言的优先级,以便在浏览器没有特殊要求时,按照顺序使用不同的语言版本回应对file1.html 的请求。这个国际化的能力实际的应用并不多。 

#
# ForceLanguagePriority allows you to serve a result page rather than
# MULTIPLE CHOICES (Prefer) [in case of a tie] or NOT ACCEPTABLE (Fallback)
# [in case no accepted languages matched the available variants]
#
ForceLanguagePriority Prefer Fallback

#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the 
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-8		#浏览器选择的标准编码 ;简体中文网站改为:GB2312 

#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-tar .tgz		#AddType参数可以为特定后缀的文件指定MIME类型,这里的设置将覆盖mime.types中的设置。 


#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
#AddEncoding x-compress .Z		  
#AddEncoding x-gzip .gz .tgz

# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
		#AddEncoding用于告诉一些使用压缩的MIME类型,这样可以让浏览器进行解压缩操作。 
		
#
# 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 scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi		#AddHandler是用于指定非静态的处理类型,用于定义文档为一个非静态的文档类型,需要进行处理,再向浏览器返回处理结果。例如上面注释中的设置是将以.cgi结尾的文件设置为cgi-script类型,那么服务器将启动这个CGI程序以进行处理。如果需要在前面AliasScript定义的路径之外执行CGI程序,就需要使用这个参数进行设置,此后以.cgi结尾的文件将被当作CGI程序执行。 
								#在配置文件、这个目录中的.htaccess以及其上级目录的.htaccess中必须允许执行CGI程序,这需要通过Options ExecCGI参数设定。 


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

#
# For type maps (negotiated resources):
# (This is enabled by default to allow the Apache "It Worked" page
#  to be distributed in multiple languages.)
#
AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

#
# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location	
# Format: Action handler-name /cgi-script/location
	#因为Apache内部提供的处理功能有限,因此可以使用Action为服务器定义外部程序作为可处理的动态文档类型,这些外部程序与标准CGI程序相同,都是对输入的数据处理之后,再输出不同MIME类型的结果。例如要定义一个对特殊后缀wri都先执行wri2txt进行处理操作,再返回结果的操作,可以使用: 
#Action windows-writer /bin/wri2txt 
#AddHandler windows-writer wri  
	#更进一步,可以直接使用Action定义对某个MIME类型预先进行处理操作,这需要例子中第一种格式的Action 参数设置方式。这样设置方式就不再需要额外的AddHandler用来将处理操作与文件后缀联系起来,而是使用Action直接处理MIME类型的文件。但如果文档后缀没有正式的MIME类型,还需要先定义一个MIME类型。 

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
		#如果客户请求的网页不存在,或者没有访问权限等情况发生时,服务器将产生一个错误代码,同时也将回应客户浏览器一个标识错误的网页。ErrorDocument就用于设置当出现哪个错误时应该回应客户浏览器那些内容,ErrorDocument的第一个参数为错误的序号,第二个参数为回应的数据,可以为简单的文本,本地网页,本地CGI程序,以及远程主机上的网页。 

#
# Putting this all together, we can internationalize error responses.
#
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
# our collection of by-error message multi-language collections.  We use 
# includes to substitute the appropriate text.
#
# You can modify the messages‘ appearance without changing any of the
# default HTTP_<error>.html.var files by adding the line:
#
#   Alias /error/include/ "/your/include/path/"
#
# which allows you to create your own set of files by starting with the
# /var/www/error/include/ files and
# copying them to /your/include/path/, even on a per-VirtualHost basis.
#

Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/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
    </Directory>

#    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_UNSUPPORTED_MEDIA_TYPE.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

</IfModule>
</IfModule>

#
# The following directives modify normal HTTP response behavior to
# handle known problems with browser implementations.
#
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命令为特定的客户程序,设置特殊的参数,以保证对老版本浏览器的兼容性,并支持新浏览器的新特性。
		
#
# The following directive disables redirects on non-GET requests for
# a directory that does not include the trailing slash.  This fixes a 
# problem with Microsoft WebFolders which does not appropriately handle 
# redirects for folders with DAV methods.
# Same deal with Apple‘s DAV filesystem and Gnome VFS support for DAV.
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>		#<Location>提供了基于URL的访问控制。
#    SetHandler server-status
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

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

#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#<IfModule mod_proxy.c>
#ProxyRequests On
#
#<Proxy *>
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Proxy>
		#Apache服务器本身就具备代理的功能,然而这要求加载入mod_proxy模块。这能使用IfModule语句进行判断,如果存在mod_proxy模块,就使用ProxyRequests打开代理支持。此后的Directory用于设置对Proxy功能的访问权限设置,以及用于设置缓冲的各个参数设置。 

#
# 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 a cache of proxied content, uncomment the following lines.
# See http://httpd.apache.org/docs/2.2/mod/mod_cache.html for more details.
#
#<IfModule mod_disk_cache.c>
#   CacheEnable disk /
#   CacheRoot "/var/cache/mod_proxy"
#</IfModule>
#

#</IfModule>
# 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 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# 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.
#
#NameVirtualHost *:80	#指定虚拟主机使用的IP地址,定义过NameVirtualHost之后,那么对这个IP地址的访问都被区分不同的虚拟主机进行处理,而对其他IP地址的访问,采用主配置的参数
#
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# 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.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.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
#</VirtualHost>
    
	#缺省设置文件中的这些内容是用于设置命名基础的虚拟主机服务器(name-based virtual host)时使用。其中NameVirtualHost 来指定虚拟主机使用的IP地址,这个IP地址将对应多个DNS名字,如果Apache使用了Listen 参数控制了多个端口,那么就可以在这里加上端口号以进一步进行区分对不同端口的不同连接请求。此后,使用 VirtualHost语句之后跟上NameVirtualHost指定的IP地址作参数,对每个名字都定义对应的虚拟主机设置。 
	#虚拟主机是在一台Web服务器上,可以为多个单独域名提供Web服务,并且每个域名都完全独立,包括具有完全独立的文档目录结构及设置,这样域名之间完全独立,不但使用每个域名访问到的内容完全独立,并且使用另一个域名无法访问其他域名提供的网页内容。虚拟主机的概念对于ISP来讲非常有用,因为虽然一个组织可以将自己的网页挂在具备其他域名的服务器上的下级网址上,但使用独立的域名和根网址更为正式,易为众人接受。传统上,必须自己设立一台服务器才能达到单独域名的目的,然而这需要维护一个单独的服务器,很多小单位缺乏足够的维护能力,更为合适的方式是租用别人维护的服务器。ISP也没有必要为一个机构提供一个单独的服务器,完全可以使用虚拟主机能力,使服务器为多个域名提供Web服务,而且不同的服务互不干扰,对外就表现为多个不同的服务器。 
   
	#有两种设定虚拟主机的方式,一种是基于HTTP 1.0标准,需要一个具备多IP地址的服务器,再配置DNS 服务器,给每个IP地址以不同的域名,最后才能配置Apache的配置文件,使服务器对不同域名返回不同的Web文档。由于这需要使用额外的IP地址,对每个要提供服务的域名都要使用单独的IP地址,因此这种方式实现起来问题较多。可以在一个网卡上绑定多个IP地址,例如使用命令:ip addr add 192.168.0.31/16 dev eth0,但此时会影响网络性能。另一种是基于HTTP 1.1标准,HTTP 1.1标准在协议中规定了对浏览器和服务器通信时,服务器能够跟踪浏览器请求的是哪个主机名字。因此可以利用这个新特性,使用更轻松的方式设定虚拟主机。这种方式不需要额外的IP地址,但需要新版本的浏览器支持。这种方式已经成为建立虚拟主机的标准方式。 
   
	#要建立非IP基础的虚拟主机,多个域名是不可少的配置,因为每个域名就对应一个要服务的虚拟主机。因此需要更改DNS服务器的配置,为服务器增加多个CNAME选项,如: 
			#freebsd IN A 192.168.1.64 
			#vhost1 IN CNAME freebsd 
			#vhost2 IN CNAME freebsd 
    
	#基本的设置选项都是为了freebsd主机设定的,如果要为vhost1和vhost2设定虚拟主机,就要使用VirtualHost语句定义不同的选项,在语句中可以使用配置文件前面讲解中的大部分选项,而可以重新定义几乎所有的针对服务器的设置。 
   
			#NameVirtualHost 192.168.1.64 
			   
			#DocumentRoot /usr/local/www/data 
			#ServerName freebsd.example.org.cn 
			   
			#DocumentRoot /vhost1 
			#ServerName vhost1.example.org.cn 
			   
			#DocumentRoot /vhost2 
			#ServerName vhost2.example.org.cn 
   
	#这里需要注意的是,VirtualHost的参数地址一定要和NameVirtualHost定义的地址相一致,必须保证所有的值严格一致,Apache服务器才承认这些定义是为这个IP地址定义的虚拟主机。此外,定义过虚拟主机之后,那么对这个IP地址的访问都被定义的虚拟主机进行处理(而不会被中心主机处理),而对其他IP地址的访问(如果这个IP未定义虚拟主机),例如127.0.0.1,才应用前面定义的(中心主机的)缺省选项。 

############################
#示例:基于多种模式虚拟主机#
############################
NameVirtualHost 192.168.0.30:80		#指定名称虚拟主机监听的IP;port,只有此项开启后,定义虚拟主机时才允许出现VirtualHost指令后的IP相同的不同虚拟主机。

<VirtualHost 192.168.0.30:80>
	ServerAdmin a.org@ljzsdut.com					#第一个虚拟主机的管理员邮箱
	DocumentRoot /www/a.org							#第一个虚拟主机目录
	ServerName www.a.org							#第一个虚拟主机域名
	ErrorLog logs//www/a.org/error_log				#第一个虚拟主机错误日志
	CustomLog logs//www/a.org/access_log common		#第一个虚拟主机访问日志
</VirtualHost>

<VirtualHost 192.168.0.30:80>						#第二个虚拟主机,与第一个构成不同主机名的虚拟主机
	ServerAdmin b.org@ljzsdut.com
	DocumentRoot /www/b.org
	ServerName www.b.org
	ErrorLog logs//www/b.org/error_log
	CustomLog logs//www/b.org/access_log common
</VirtualHost>

<VirtualHost 192.168.0.31:80>						#第三个虚拟主机,与第一个构成不同IP的虚拟主机
	ServerAdmin c.org@ljzsdut.com
	DocumentRoot /www/c.org
	ServerName www.c.org
	ErrorLog logs//www/c.org/error_log
	CustomLog logs//www/c.org/access_log common
</VirtualHost>

<VirtualHost 192.168.0.30:8080>						#第四个虚拟主机,与第一个构成不同端口的虚拟主机
	ServerAdmin d.org@ljzsdut.com
	DocumentRoot /www/d.org
	ServerName www.d.org
	ErrorLog logs//www/c.org/error_log
	CustomLog logs//www/c.org/access_log common
</VirtualHost>


httpd配置文件详解(v2.2)