Apache配置文件詳解


配置文件目錄

conf/                          # apache配置conf配置文件目錄
├── extra                        # 額外的apache配置文件目錄 如:httpd-vhost.conf
│   ├── httpd-autoindex.conf                 # 配置目錄列表的輔配置文件
│   ├── httpd-dav.conf               # dav支持配置
│   ├── httpd-default.conf             # 這個文件里配置的是apache的相關服務參數:超時時間、保持鏈接
│   ├── httpd-info.conf                      # 配置用於服務器信息和狀態顯示的輔配置文件
│   ├── httpd-languages.conf             # 語言支持
│   ├── httpd-manual.conf                    # 配置提供Apache文檔訪問的輔配置文件
│   ├── httpd-mpm.conf                       # 服務器池管理,也是優化apache的一個配置文件(apache的模式以及配置鏈接數,常用模式為worker模式和profork模式,默認porfork)
│   ├── httpd-multilang-errordoc.conf        # 配置多語言錯誤應答的輔配置文件
│   ├── httpd-ssl.conf                       # 提供apache ssl支持配置文件
│   ├── httpd-userdir.conf                   # 配置用戶主目錄的輔配置文件
│   ├── httpd-vhosts.conf                    # 虛擬機的配置文件
│   └── proxy-html.conf
├── httpd.conf                               # apache主配置文件
├── magic
├── mime.types
└── original
    ├── extra
    │   ├── httpd-autoindex.conf
    │   ├── httpd-dav.conf
    │   ├── httpd-default.conf
    │   ├── httpd-info.conf
    │   ├── httpd-languages.conf
    │   ├── httpd-manual.conf
    │   ├── httpd-mpm.conf
    │   ├── httpd-multilang-errordoc.conf
    │   ├── httpd-ssl.conf
    │   ├── httpd-userdir.conf
    │   ├── httpd-vhosts.conf
    │   └── proxy-html.conf
    └── httpd.conf

原版httpd.conf

# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/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.  
#
# 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/access_log"
# with ServerRoot set to "/usr/local/apache2" will be interpreted by the
# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" 
# will be interpreted as '/logs/access_log'.

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "/usr/local/apache/"

#
# Mutex: Allows you to set the mutex mechanism and mutex file directory
# for individual mutexes, or change the global defaults
#
# Uncomment and change the directory if mutexes are file-based and the default
# mutex file directory is not on a local disk or is not appropriate for some
# other reason.
#
# Mutex default:logs

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of 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.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# 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 authn_file_module modules/mod_authn_file.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_socache_module modules/mod_authn_socache.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
#LoadModule authz_dbd_module modules/mod_authz_dbd.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_form_module modules/mod_auth_form.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule allowmethods_module modules/mod_allowmethods.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule cache_module modules/mod_cache.so
#LoadModule cache_disk_module modules/mod_cache_disk.so
#LoadModule cache_socache_module modules/mod_cache_socache.so
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
#LoadModule socache_dbm_module modules/mod_socache_dbm.so
#LoadModule socache_memcache_module modules/mod_socache_memcache.so
#LoadModule socache_redis_module modules/mod_socache_redis.so
#LoadModule watchdog_module modules/mod_watchdog.so
#LoadModule macro_module modules/mod_macro.so
#LoadModule dbd_module modules/mod_dbd.so
#LoadModule dumpio_module modules/mod_dumpio.so
#LoadModule buffer_module modules/mod_buffer.so
#LoadModule ratelimit_module modules/mod_ratelimit.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
#LoadModule request_module modules/mod_request.so
#LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule sed_module modules/mod_sed.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_debug_module modules/mod_log_debug.so
#LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
#LoadModule remoteip_module modules/mod_remoteip.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
#LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_express_module modules/mod_proxy_express.so
#LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
#LoadModule session_module modules/mod_session.so
#LoadModule session_cookie_module modules/mod_session_cookie.so
#LoadModule session_dbd_module modules/mod_session_dbd.so
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
#LoadModule ssl_module modules/mod_ssl.so
#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
#LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
LoadModule unixd_module modules/mod_unixd.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 cgid_module modules/mod_cgid.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

<IfModule unixd_module>
#
# 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.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon

</IfModule>

# '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 you@example.com

#
# 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 your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

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

#
# 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 "/usr/local/apache//htdocs"
<Directory "/usr/local/apache//htdocs">
    #
    # 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.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ".ht*">
    Require all denied
</Files>

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

<IfModule log_config_module>
    #
    # 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
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # 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 prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.example.com/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target 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/ "/usr/local/apache//cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock cgisock
</IfModule>

#
# "/usr/local/apache//cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/apache//cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    #
    # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied
    # backend servers which have lingering "httpoxy" defects.
    # 'Proxy' request header is undefined by the IETF, not listed by IANA
    #
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #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

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

    # For type maps (negotiated resources):
    #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
</IfModule>

#
# 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.
#
#MIMEMagicFile conf/magic

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

#
# MaxRanges: Maximum number of Ranges in a request before
# returning the entire resource, or one of the special
# values 'default', 'none' or 'unlimited'.
# Default setting is to accept 200 Ranges.
#MaxRanges unlimited

#
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall may be used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
#EnableSendfile on

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be 
# included to add extra features or to modify the default configuration of 
# the server, or you may simply copy their contents here and change as 
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

配置文件詳解

# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/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.  
#
# 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/access_log"
# with ServerRoot set to "/usr/local/apache2" will be interpreted by the
# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" 
# will be interpreted as '/logs/access_log'.

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
# 用於指定Apache的運行目錄,服務啟動之后自動將目錄改變為當前目錄,在后面使用到的所有相對路徑都是想對這個目錄下
ServerRoot "/usr/local/apache/"

#
# Mutex: Allows you to set the mutex mechanism and mutex file directory
# for individual mutexes, or change the global defaults
#
# Uncomment and change the directory if mutexes are file-based and the default
# mutex file directory is not on a local disk or is not appropriate for some
# other reason.
#
# Mutex default:logs

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of 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.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# 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
# 加載特定的DSO模塊。Apache默認將已編譯的DSO模塊存放於4.1目錄結構小節中所示的動態加載模塊目錄中。
# 語法 :LoadModule module filename 如果filename使用相對路徑,則路徑是相對於ServerRoot所指示的相對路徑。
# Apache配置文件默認加載所有已編譯的DSO模塊,筆者建議只加載如下模塊:authn_file、authn_default、 authz_host、authz_user、authz_default、auth_basic、dir、alias
、filter、speling、 log_config、env、vhost_alias、setenvif、mime、negotiation、rewrite、deflate、 expires、headers、cache、file-cache、disk-cache、mem-cache。
# 各模塊說明詳解https://httpd.apache.org/docs/2.4/mod/
# 如果需要提供基於文本文件的認證,加載此模塊,否則注釋掉
LoadModule authn_file_module modules/mod_authn_file.so
# 如果需要提供基於DBM文件的認證,加載此模塊,否則注釋掉
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
# 如果需要提供匿名用戶認證,加載此模塊,否則注釋掉
#LoadModule authn_anon_module modules/mod_authn_anon.so
# 如果需要提供基於SQL數據庫的認證,加載此模塊,否則注釋掉
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
# 
#LoadModule authn_socache_module modules/mod_authn_socache.so
# 
LoadModule authn_core_module modules/mod_authn_core.so
# 此模塊提供基於主機名、IP地址、請求特征的訪問控制,Allow、Deny指令需要,推薦加載。
LoadModule authz_host_module modules/mod_authz_host.so
# 如果需要使用純文本文件為組提供授權支持,加載此模塊,否則注釋掉
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
# 如果需要提供基於每個用戶的授權支持,加載此模塊,否則注釋掉
LoadModule authz_user_module modules/mod_authz_user.so
# 如果需要使用DBM文件為組提供授權支持,加載此模塊,否則注釋掉
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
# 如果需要基於文件的所有者進行授權,加載此模塊,否則注釋掉
#LoadModule authz_owner_module modules/mod_authz_owner.so
# 如果需要使用DBD文件為組提供授權支持,加載此模塊,否則注釋掉
#LoadModule authz_dbd_module modules/mod_authz_dbd.so

LoadModule authz_core_module modules/mod_authz_core.so

LoadModule access_compat_module modules/mod_access_compat.so
# 如果需要提供基本的HTTP認證,加載此模塊,否則注釋掉,此模塊至少需要同時加載一個認證支持模塊和一個授權支持模塊
LoadModule auth_basic_module modules/mod_auth_basic.so

#LoadModule auth_form_module modules/mod_auth_form.so
# 如果需要提供HTTP MD5摘要認證,加載此模塊,否則注釋掉,此模塊至少需要同時加載一個認證支持模塊和一個授權支持模塊
#LoadModule auth_digest_module modules/mod_auth_digest.so

#LoadModule allowmethods_module modules/mod_allowmethods.so
# 此模塊提供文件描述符緩存支持,從而提高Apache性能,推薦加載,但請小心使用
#LoadModule file_cache_module modules/mod_file_cache.so
# 此模塊提供基於URI鍵的內容動態緩存(內存或磁盤),從而提高Apache性能,必須與mod_disk_cache/mod_mem_cache同時使用,推薦加載
#LoadModule cache_module modules/mod_cache.so
# 此模塊為mod_cache提供基於磁盤的緩存管理,推薦加載
#LoadModule cache_disk_module modules/mod_cache_disk.so
# 此模塊為mod_cache提供基於內存的緩存管理,推薦加載
#LoadModule cache_socache_module modules/mod_cache_socache.so

#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

#LoadModule socache_dbm_module modules/mod_socache_dbm.so

#LoadModule socache_memcache_module modules/mod_socache_memcache.so

#LoadModule watchdog_module modules/mod_watchdog.so

#LoadModule macro_module modules/mod_macro.so
# 如果需要管理SQL數據庫連接,為需要數據庫功能的模塊提供支持,加載此模塊,否則注釋掉(推薦)
#LoadModule dbd_module modules/mod_dbd.so
# 此模塊將所有I/O操作轉儲到錯誤日志中,會導致在日志中寫入及其海量的數據,只建議在發現問題並進行調試的時候使用
#LoadModule dumpio_module modules/mod_dumpio.so

#LoadModule buffer_module modules/mod_buffer.so

#LoadModule ratelimit_module modules/mod_ratelimit.so

LoadModule reqtimeout_module modules/mod_reqtimeout.so
# 如果需要使用外部程序作為過濾器,加載此模塊(不推薦),否則注釋掉
#LoadModule ext_filter_module modules/mod_ext_filter.so

#LoadModule request_module modules/mod_request.so
# 如果需要實現服務端包含文檔(SSI)處理,加載此模塊(不推薦),否則注釋掉
#LoadModule include_module modules/mod_include.so
# 如果需要根據上下文實際情況對輸出過濾器進行動態配置,加載此模塊,否則注釋掉
LoadModule filter_module modules/mod_filter.so

#LoadModule substitute_module modules/mod_substitute.so

#LoadModule sed_module modules/mod_sed.so
# 如果需要服務器在將輸出內容發送到客戶端以前進行壓縮以節約帶寬,加載此模塊(推薦),否則注釋掉
#LoadModule deflate_module modules/mod_deflate.so
# 如果需要根據文件擴展名決定應答的行為(處理器/過濾器)和內容(MIME類型/語言/字符集/編碼),加載此模塊,否則注釋掉
LoadModule mime_module modules/mod_mime.so
# 如果需要記錄日志和定制日志文件格式,加載此模塊(推薦),否則注釋掉
LoadModule log_config_module modules/mod_log_config.so

#LoadModule log_debug_module modules/mod_log_debug.so
# 如果需要對每個請求的輸入/輸出字節數以及HTTP頭進行日志記錄,加載此模塊,否則注釋掉
#LoadModule logio_module modules/mod_logio.so
# 如果允許Apache修改或清除傳送到CGI腳本和SSI頁面的環境變量,加載此模塊,否則注釋掉
LoadModule env_module modules/mod_env.so
# 如果允許通過配置文件控制HTTP的"Expires:"和"Cache-Control:"頭內容,加載此模塊(推薦),否則注釋掉
#LoadModule expires_module modules/mod_expires.so
# 如果允許通過配置文件控制任意的HTTP請求和應答頭信息,加載此模塊,否則注釋掉
LoadModule headers_module modules/mod_headers.so

#LoadModule unique_id_module modules/mod_unique_id.so
# 如果需要根據客戶端請求頭字段設置環境變量,加載此模塊,否則注釋掉
LoadModule setenvif_module modules/mod_setenvif.so

LoadModule version_module modules/mod_version.so

#LoadModule remoteip_module modules/mod_remoteip.so

#LoadModule proxy_module modules/mod_proxy.so

#LoadModule proxy_connect_module modules/mod_proxy_connect.so

#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

#LoadModule proxy_http_module modules/mod_proxy_http.so

#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

#LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so

#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so

#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
# 此模塊是mod_proxy的擴展,提供Apache JServ Protocol支持,只在必要時加載
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
# 此模塊是mod_proxy的擴展,提供負載均衡支持,只在必要時加載
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

#LoadModule proxy_express_module modules/mod_proxy_express.so

#LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so

#LoadModule session_module modules/mod_session.so

#LoadModule session_cookie_module modules/mod_session_cookie.so

#LoadModule session_dbd_module modules/mod_session_dbd.so

#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

#LoadModule ssl_module modules/mod_ssl.so

#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so

#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so

#LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so

LoadModule unixd_module modules/mod_unixd.so
# 如果允許Apache提供DAV協議支持,加載此模塊,否則注釋掉
#LoadModule dav_module modules/mod_dav.so
# 此模塊生成描述服務器狀態的Web頁面,只建議在追蹤服務器性能和問題時加載
LoadModule status_module modules/mod_status.so
# 如果需要自動對目錄中的內容生成列表(類似於"ls"或"dir"命令),加載此模塊(會帶來安全問題,不推薦),否則注釋掉
LoadModule autoindex_module modules/mod_autoindex.so
# 如果需要生成Apache配置情況的Web頁面,加載此模塊(會帶來安全問題,不推薦),否則注釋掉
#LoadModule info_module modules/mod_info.so
# 此模塊在線程型MPM(worker)上用一個外部CGI守護進程執行CGI腳本,如果正在多線程模式下使用CGI程序,推薦替換mod_cgi加載,否則注釋掉  
#LoadModule cgid_module modules/mod_cgid.so
# 此模塊為mod_dav訪問服務器上的文件系統提供支持,如果加載mod_dav,則也應加載此模塊,否則注釋掉
#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
# 如果需要針對特定的媒體類型或請求方法執行CGI腳本,加載此模塊,否則注釋掉
#LoadModule actions_module modules/mod_actions.so
# 如果希望服務器自動糾正URL中的拼寫錯誤,加載此模塊(推薦),否則注釋掉
#LoadModule speling_module modules/mod_speling.so
# 如果允許在URL中通過"/~username"形式從用戶自己的主目錄中提供頁面,加載此模塊,否則注釋掉
#LoadModule userdir_module modules/mod_userdir.so
# 此模塊提供從文件系統的不同部分到文檔樹的映射和URL重定向,推薦加載
LoadModule alias_module modules/mod_alias.so
# 如果需要基於一定規則實時重寫URL請求,加載此模塊(推薦),否則注釋掉
#LoadModule rewrite_module modules/mod_rewrite.so

<IfModule unixd_module>
#
# 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.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon

</IfModule>

# '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 you@example.com

#
# 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 your host doesn't have a registered DNS name, enter its IP address here.
#
# 設置服務器用於辨識自己的主機名和端口號。
# 當沒有指定ServerName時,服務器會嘗試對IP地址進行反向查詢來推斷主機名。如果在ServerName中沒有指定端口號,服務器會使用接受請求的那個端口。
#ServerName www.example.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
# <Directory>和</Directory>用於封裝一組指令,使之僅對某個目錄及其子目錄生效。
# 語法:<Directory Directory-path> ... </Directory>
# Directory-path可以是一個目錄的完整路徑,或是包含了Unix shell匹配語法的通配符字符串。
# <Directory>指令不可被嵌套使用,也不能出現在<Limit>或<LimitExcept>配置段中。
# 詳解參數,見下文
<Directory />
    AllowOverride none
    Require all denied
</Directory>

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

#
# 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 "/usr/local/apache//htdocs"
<Directory "/usr/local/apache//htdocs">
    #
    # 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
    #  
    # for more information.
    # 參數下述詳解
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    # 參數下述詳解
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
# 封裝根據指定的模塊是否啟用而決定是否生效的指令。
# 在<IfModule>配置段中的指令僅當測試結果為真的時候才進行處理,否則所有其間的指令都將被忽略。
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
# 提供基於文件名的訪問控制,類似於<Directory>和<Location>指令。
# 語法:<Files filename> ... </Files>
# filename參數應當是一個文件名或是一個包含通配符的字符串,其中"?"匹配任何單個字符,"*"匹配任何字符串序列。在"~"字符之后可以使用正則表達式。
# 在此配置段中定義的指令將作用於其基本名稱(不是完整的路徑)與指定的文件名相符的對象。<Files>段將根據它們在配置文件中出現的順序被處理:在<Directory>段和.htaccess
<Files ".ht*">
    Require all denied
</Files>

#
# 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 info ,則所有notice和warn級別的信息也會被記錄。
LogLevel warn
        可以選擇下列level,依照重要性降序排列:
           emerg  緊急(系統無法使用)
           alert    必須立即采取措施
           crit      致命情況
           error    錯誤情況
           warn    警告情況
           notice  一般重要情況
           info     普通信息
           debug   調試信息
        
# 見下文有詳解
<IfModule log_config_module>
    #
    # 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
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # 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 prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    # 映射URL到文件系統的特定區域。
    # 語法:Alias URL-path file-path|directory-path
    # Alias指令使文檔可以被存儲在DocumentRoot以外的本地文件系統中。以(%已解碼的)url-path路徑開頭的URL可以被映射到以directory-path開頭的本地文件。
    # 如果對在DocumentRoot之外的某個目錄建立了一個Alias ,則可能需要通過<Directory>段明確的對目標目錄設定訪問權限。
    
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.example.com/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    # ScriptAlias 映射一個URL到文件系統並視之為CGI腳本目錄
    # 語法:ScriptAlias URL-path file-path|directory-path
    # ScriptAlias指令的行為與Alias指令相同,但同時它又標明此目錄中含有應該由cgi-script處理器處理的CGI腳本。以URL-path開頭的(%已解碼的)的URL會被映射到由第二個參數指定的具有完整路徑名的本地文件系統中的腳本。
    # ScriptSock:在以線程式MPM(worker)運行的Apache中設置用來與CGI守護進程通信的套接字文件名前綴(其后附加父進程 PID組成完整的文件名)。這個套接字將會用啟動Apache服
        # 務器的父進程用戶權限(通常是root)打開。為了維護與CGI腳本通訊的安全性,不允許其他用戶擁有寫入套接字所在目錄的權限是很重要的。
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target 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.
    # 設定默認CGI腳本目錄及別名
    ScriptAlias /cgi-bin/ "/usr/local/apache//cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    # 在以線程式MPM(worker)運行的Apache中設置用來與CGI守護進程通信的套接字文件名前綴
    #Scriptsock cgisock
</IfModule>

#
# "/usr/local/apache//cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/apache//cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    #
    # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied
    # backend servers which have lingering "httpoxy" defects.
    # 'Proxy' request header is undefined by the IETF, not listed by IANA
    #
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #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

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

    # For type maps (negotiated resources):
    #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
</IfModule>

#
# 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.
#
#MIMEMagicFile conf/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
# 批示當遇到錯誤的時候服務器將給客戶端什么樣的應答
# 語法:ErrorDocument error-code document
    # error-code 服務器返回的錯誤代碼 
    # document  可以由一個斜杠(/)開頭來指示一個本地URL(相對於DocumentRoot),或是提供一個能被客戶端解釋的完整的URL
    # 此外還能提供一個可以被瀏覽器顯示的消息。
#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
#

#
# MaxRanges: Maximum number of Ranges in a request before
# returning the entire resource, or one of the special
# values 'default', 'none' or 'unlimited'.
# Default setting is to accept 200 Ranges.
#MaxRanges unlimited

# 指示httpd在遞送中如果需要讀取一個文件的內容,它是否可以使用內存映射
# 語法:EnableMMAP On|Off
""" 當處理一個需要訪問文件中的數據的請求時,比如說當遞送一個使用mod_include進行服務器端分析的文件時,如果操作系統支持,Apache將默認使用內存映射。
    這種內存映射有時會帶來性能的提高,但在某些情況下,您可能會需要禁用內存映射以避免一些操作系統的問題:
    在一些多處理器的系統上,內存映射會減低一些httpd的性能;
    在掛載了NFS的DocumentRoot上,若已經將一個文件進行了內存映射,則刪除或截斷這個文件會造成httpd因為分段故障而崩潰。
    在可能遇到這些問題的服務器配置過程中,應當使用下面的命令來禁用內存映射
對於掛載了NFS的文件夾,可以單獨在<directory>段中指定禁用內存映射:
     <Directory "/path-to-nfs-files"> 
         EnableMMAP Off
     </Directory>      
"""
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall may be used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
"""
EnableSendfile
控制httpd是否可以使用操作系統內核的sendfile支持來將文件發送到客戶端。
默認情況下,當處理一個請求並不需要訪問文件內部的數據時(比如發送一個靜態的文件內容),如果操作系統支持,Apache將使用sendfile將文件內容直接發送到客戶端而並不讀取文件。
這個sendfile機制避免了分開的讀和寫操作以及緩沖區分配,但是在一些平台或者一些文件系統上,最好禁止這個特性來避免一些問題:
    1、一些平台可能會有編譯系統檢測不到的有缺陷的sendfile支持,特別是將在其他平台上使用交叉編譯得到的二進制文件運行於當前對sendfile支持有缺陷的平台時;
    2、在Linux上啟用IPv6時,使用sendfile將會觸發某些網卡上的TCP校驗和卸載bug;
    3、當Linux運行在Itanium處理器上的時候,sendfile可能無法處理大於2GB的文件;
    4、對於一個通過網絡掛載了NFS文件系統的DocumentRoot (比如:NFS或SMB),內核可能無法可靠的通過自己的緩沖區服務於網絡文件。
如果出現以上情況,你應當禁用sendfile
針對NFS或SMB,可以單獨在<directory>段中指定禁用:
    <Directory "/path-to-nfs-files">
        EnableSendfile Off
    </Directory>
"""
#EnableSendfile on

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be 
# included to add extra features or to modify the default configuration of 
# the server, or you may simply copy their contents here and change as 
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

 配置文件訪問控制

注意:使用require指令時,需要在指令外添加<RequireAll></RequireAll>標簽對,否則重啟Apache2.4加載規則時將出現錯誤:" negative Require directive has no effect in <RequireAny> directive "==========基於Httpd Version2.4的訪問控制==========
Require 指令
Require all granted 無條件允許訪問
Require all denied 無條件拒絕訪問
Require env env-var [env-var] ... 僅當設置了給定的環境變量之一時才允許訪問。
Require method http-method [http-method] ... 僅允許對給定的 HTTP 方法進行訪問。
Require expr expression 如果表達式的計算結果為真,則允許訪問。
Require user userid [userid] ... 只有指定用戶才能訪問資源。
Require group group-name [group-name] ... 只有命名組中的用戶才能訪問資源。
Require valid-user 所有有效用戶都可以訪問該資源。
Require ip 10 172.20 192.168.2 指定 IP 地址范圍內的客戶端可以訪問該資源。
Require forward-dns dynamic.example.org 從名稱 dynamic.example.org 解析出 IP 的客戶端將被授予訪問權限。

例:
# 表示,拒絕所有訪問,只允許192.168.1.0/24網段訪問
<RequireAll>
    Require all denied
    Require ip 192.168.1.0/24 
</RequireAll>

# 表示,允許所有訪問,只拒絕192.168.1.0/24網段訪問
<RequireAll>
    Require all granted
    Require not ip 192.168.1.0/24 
</RequireAll>

Options指令

Options指令
Options指令控制了在特定目錄中將使用哪些服務器特性
    - All              除MultiViews之外的所有特性。這是默認設置
    - ExecCGI          允許在該目錄下執行CGI腳本
    - FollowSymLinks   服務器會在此目錄中使用符號連接(在當前目錄下文件 test.html 鏈接至其它目錄文件test.html)。如果此配置位於<Location>配置段中,則此設置會被忽略
    - Includes         許服務器端包含功能
    - IncludesNoExec   允許服務器端包含功能,但禁用執行CGI腳本
    - Indexes          如果一個映射到目錄的URL被請求,如果沒有index.html,那么服務器會返回一個格式化后的目錄 列表
    - MultiViews       允許內容協商的多重視圖 (MultiViews其實是Apache的一個智能特性。當客戶訪問目錄 中一個不存在的對象時,如訪問“http://192.168.16.177/icons/a”,則Apache會查找這個目錄下所有a.*文件。由於 icons目錄下存在a.gif文件,因此Apache會將a.gif文件返回給客戶,而不是返回出錯信息)
    - SymLinksIfOwnerMatch 服務器僅在符號連接與其目的目錄或文件擁有者具有同樣的用戶id時才使用它
如果所有施用於  Options  指令的可選項前都加有+或-符號,此可選項將被合並。如下:
<Directory /web/docs>
  Options Indexes FollowSymLinks
</Directory>
<Directory /web/docs/spec>
  Options Includes  
</Directory>  
則只有Includes  設置到/web/docs/spec目錄上。
<Directory /web/docs>
  Options Indexes FollowSymLinks
  </Directory>  
<Directory /web/docs/spec>
  Options +Includes -Indexes
</Directory>  
那么就會有 FollowSymLinks和Includes設置到/web/docs/spec目錄上
############注意事項############
1、主目錄設置了Indexes權限,且主目錄中並不存在默認文檔,但訪問時並不會出現目錄列表,而只出現Apache的測試頁面。
2、一旦定義允許目錄瀏覽,就會將Web站點的文件夾和文件名結構暴露給黑客。目錄瀏覽還會允許黑客瀏覽文件並掌握服務器配置信息,所以指定該權限往往帶來安全性上的隱患。除非有充足的理由要使用目錄瀏覽,否則應該禁用它。
############----############

AllowOverride 指令

AllowOverride選項用於定義位於每個目錄下.htaccess(訪問控制)文件中的指令類型。基於安全和效率的原因,雖然可以通 過.htaccess來設置目錄的訪問權限,但應盡可能地避免使用.htaccess文件
所以一般將AllowOverride設置為”None”,即 禁止使用.htaccess文件,而將目錄權限的設置放在主配置文件httpd.conf的<Directory> 和</Directory>語句之間。
    - None 網站 .htaccess 文件將被完全忽略
    - All 所有具有 .htaccess 作用域的指令都允許出現在 .htaccess 文件中
    - AuthConfig 允許使用與認證授權相關的指令(AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile, AuthName, AuthType, AuthUserFile, Require, 等)
    - FileInfo 允許使用控制文檔類型的指令(DefaultType, ErrorDocument, ForceType, LanguagePriority, SetHandler, SetInputFilter, SetOutputFilter,
                                 mod_mime中的 Add* 和 Remove* 指令等等)、控制文檔元數據的指令(Header, RequestHeader, SetEnvIf, SetEnvIfNoCase, BrowserMatch, 
                                 CookieExpires, CookieDomain, CookieStyle, CookieTracking, CookieName)、mod_rewrite中的指令(RewriteEngine,
                                  RewriteOptions, RewriteBase, RewriteCond, RewriteRule)和mod_actions中的Action指令
    - Indexes 允許使用控制目錄索引的指令(AddDescription, AddIcon, AddIconByEncoding, AddIconByType, DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName,
                                 IndexIgnore, IndexOptions, ReadmeName, 等)
    - Limit 允許使用控制主機訪問的指令(Allow, Deny, Order)。 一般 Apache 新安裝 AllowOverride 默認為「None」

容器指令

容器相關指令:<Directory> <DirectoryMatch> <Files> <FilesMatch> <IfDefine> <IfModule> <Location> <LocationMatch> <Proxy> <ProxyMatch> <VirtualHost>

<Directory>文件系統容器
<Directory>和<Files>是針對文件系統的指令。<Directory>段中的指令作用於指定的文件系統目錄及其所有子目錄,.htaccess 文件可以達到同樣的效果
例1: /var/web/dir1及其所有子目錄被允許目錄列表
<Directory /var/web/dir1>
    Options +Indexes 允許目錄列表(加號允許、減號禁止)
</Directory>
例2: /var/web/dir1 目錄下支持鏈接符號訪問
<Directory /var/web/dir1>
    Options FollowSysLinks 允許符號鏈接(在當前目錄下文件 test.html 鏈接至其它目錄文件test.html)
</Directory>

<Files>段中的指令作用於特定的文件名,而無論這個文件實際存在於哪個目錄 <Files>段將根據它們在配置文件中出現的順序被處理,在<Directory>段和.htaccess文件被處理之后,但在<Location>段之前 請注意:<Files>能嵌入到<Directory>段中以限制它們作用的文件系統范圍 例1: 下例中的配置指令如果出現在配置文件的主服務器段,則會拒絕對位於任何目錄下的private.html的訪問。 <Files private.html> Require all denied </Files> 例2: 下例中的配置指令 會拒絕對任何目錄下 以 .ht 類型結尾的文件 <Files ".ht*">     Require all denied </Files> 例3: < Files>和<Directory>段的組合可以作用於文件系統中的特定文件 /var/web/dir1/private.html, /var/web/dir1/subdir2/private.html, /var/web/dir1/subdir3/private.html 拒絕任何/var/web/dir1/目錄下的private.html的訪問 <Directory /var/web/dir1> <Files private.html> Require all denied </Files> </Directory>
<Location>網絡空間容器(將封裝的指令作用於匹配的URL) 語法: <Location URL-path|URL> ... </Location> 例1: 配置會拒絕任何對以/private開頭的URL的訪問 http://yoursite.example.com/private,  http://yoursite.example.com/private123,  http://yoursite.example.com/private/dir/file.html <Location /private> Require all denied </Location>
<Directory>,<Files>, 和<Location>指令可以支持正則表達式 例1: 正則表達式一次性拒絕對多種圖形文件的訪問 <FilesMatch .(?i:gif|jpe?g|png)$> Require all denied </FilesMatch> 如何選擇容器? 可以參考:當指令應該作用於文件系統時,總是用<Directory>或者<Files>;而當指令作用於不存在於文件系統的對象時,就用<Location>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM