天天看點

Linux下Apache 配置檔案詳解

### Section 1: Global Environment

//當伺服器響應主機頭(header)資訊時顯示Apache的版本和作業系統名稱

ServerTokens OS

//設定伺服器的根目錄

ServerRoot "/etc/httpd"

#ScoreBoardFile run/httpd.scoreboard

//設定運作Apache時使用的PidFile的路徑

PidFile run/httpd.pid

//若300秒後沒有收到或送出任何資料就切斷該連接配接

Timeout 300

//不使用保持連接配接的功能,即客戶一次請求連接配接隻能響應一個檔案

/建議使用者将此參數的值設定為On,即允許使用保持連接配接的功能

KeepAlive Off

//在使用保持連接配接功能時,設定客戶一次請求連接配接能響應檔案的最大上限

MaxKeepAliveRequests 100

//在使用保持連接配接功能時,兩個相鄰的連接配接的時間間隔超過15秒,就切斷連接配接

KeepAliveTimeout 15

##

## Server-Pool Size Regulation (MPM specific)

##

# prefork MPM

# StartServers: number of server processes to start

# MinSpareServers: minimum number of server processes which are kept spare

# MaxSpareServers: maximum number of server processes which are kept spare

# MaxClients: maximum number of server processes allowed to start

# MaxRequestsPerChild: maximum number of requests a server process serves

//設定使用Prefork MPM運作方式的參數,此運作方式是Red hat預設的方式

<IfModule prefork.c>

//設定伺服器啟動時運作的程序數

StartServers 8

//Apache在運作時會根據負載的輕重自動調整空閑子程序的數目

//若存在低于5個空閑子程序,就建立一個新的子程序準備為客戶提供服務

MinSpareServers 5

//若存在高于20個空閑子程序,就建立逐一删除子程序來提高系統性能

MaxSpareServers 20

//限制同一時間的連接配接數不能超過150

MaxClients 150

//限制每個子程序在結束處理請求之前能處理的連接配接請求為1000

MaxRequestsPerChild 1000

</IfModule>

# worker MPM

# StartServers: initial number of server processes to start

//設定使用Worker MPM運作方式的參數

<IfModule worker.c>

StartServers 2

MaxClients 150

MinSpareThreads 25

MaxSpareThreads 75

ThreadsPerChild 25

MaxRequestsPerChild 0

</IfModule>

# perchild MPM

# NumServers: constant number of server processes

//設定使用perchild MPM運作方式的參數

<IfModule perchild.c>

NumServers 5

StartThreads 5

MinSpareThreads 5

MaxSpareThreads 10

MaxThreadsPerChild 20

MaxRequestsPerChild 0

</IfModule>

//設定伺服器的監聽端口

#Listen 12.34.56.78:80

Listen 202.112.85.101:80

#

# Load config files from the config directory "/etc/httpd/conf.d".

//将/etc/httpd/conf.d目錄下所有以conf結尾的配置檔案包含進來

Include conf.dpublic_html>

# AllowOverride FileInfo AuthConfig Limit

# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

# <Limit GET POST OPTIONS>

# Order allow,deny

# Allow from all

# </Limit>

# <LimitExcept GET POST OPTIONS>

# Order deny,allow

# Deny from all

# </LimitExcept>

#</Directory>

//當通路伺服器時,依次查找頁面Index.html index.htm.var

DirectoryIndex index.html index.html.var

//指定保護目錄配置檔案的名稱

AccessFileName .htaccess

//拒絕通路以.ht開頭的檔案,即保證.htaccess不被通路

<Files ~ "^.ht">

Order allow,deny

Deny from all

</Files>

//指定負責處理MIME對應格式的配置檔案的存放位置

TypesConfig /etc/mime.types

//指定預設的MIME檔案類型為純文字或HTML檔案

DefaultType text/plain

//當mod_mime_magic.c子產品被加載時,指定magic資訊碼配置檔案的存放位置

<IfModule mod_mime_magic.c>

# MIMEMagicFile /usr/share/magic.mime

MIMEMagicFile conf/magic

</IfModule>

//隻記錄連接配接Apache伺服器的Ip位址,而不紀錄主機名

HostnameLookups Off

//指定錯誤日志存放位置

ErrorLog logs/error_log

//指定記錄的錯誤資訊的詳細等級為warn等級

LogLevel warn

//定義四中記錄日志的格式

LogFormat "%h %l %u %t "%r" %>s %b "%{ Referer }i" "%{ User-Agent }i"" combined

LogFormat "%h %l %u %t "%r" %>s %b" common

LogFormat "%{ Referer }i -> %U" referer

LogFormat "%{ User-agent }i" agent

//指定通路日志的紀錄格式為combined(混合型),并指定通路日志存放位置

# CustomLog logs/access_log common

CustomLog logs/access_log combined

#CustomLog logs/referer_log referer

#CustomLog logs/agent_log agent

#CustomLog logs/access_log combined

//設定apache自己産生的頁面中使用apache伺服器版本的簽名

ServerSignature On

//設定内容協商目錄的通路别名

Alias /icons/ "/var/www/icons/"

//設定/var/www/icons/的通路權限

<Directory "/var/www/icons">

//MultiViews 使用内容協商功決定被發送的網頁的性質

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

//設定網頁郵件服務

Alias /webmail "/usr/share/squirrelmail"

<Directory "/usr/share/squirrelmail">

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

//設定apache手冊的通路别名

Alias /manual "/var/www/manual"

<Directory "/var/www/manual">

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

//設定浏覽器比對

BrowserMatch "Mozilla/2" nokeepalive

BrowserMatch "MSIE 4.0b2;" nokeepalive downgrade-1.0 force-response-1.0

BrowserMatch "RealPlayer 4.0" force-response-1.0

BrowserMatch "Java/1.0" force-response-1.0

BrowserMatch "JDK/1.0" force-response-1.0

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully

BrowserMatch "^WebDrive" redirect-carefully

#

# Allow server status reports, with the URL of http://servername/server-s...

# Change the ".your-domain.com" to match your domain to enable.

#

#<Location /server-status>

# SetHandler server-status

# Order deny,allow

# Deny from all

# Allow from .your-domain.com

#</Location>

#

# Allow remote server configuration reports, with the URL of

# http://servername/server-i... (requires that mod_info.c be loaded).

# Change the ".your-domain.com" to match your domain to enable.

#

#<Location /server-info>

# SetHandler server-info

# Order deny,allow

# Deny from all

# Allow from .your-domain.com

#</Location>

//設定APache為代理伺服器

# 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 .your-domain.com

#</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 the cache as well, edit and uncomment the following lines:

# (no cacheing without CacheRoot)

#

#CacheRoot "/etc/httpd/proxy"

#CacheSize 5

#CacheGcInterval 4

#CacheMaxExpire 24

#CacheLastModifiedFactor 0.1

#CacheDefaultExpire 1

#NoCache a-domain.com another-domain.edu joes.garage-sale.com

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

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

#

# Use name-based virtual hosting.

//指令監聽本地計算機上所有的IP位址請求

#NameVirtualHost *

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#

#<VirtualHost *>

//定義虛拟主機的設定,此設定将覆寫前面有的的相同指令

# ServerAdmin webmaster at dummy-host dot example.com

# DocumentRoot /www/docs/dummy-host.example.com

# ServerName dummy-host.example.com

# ErrorLog logs/dummy-host.example.com-error_log

# CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

//指定DAV加鎖資料庫檔案的存放位置

<IfModule mod_dav_fs.c>

# Location of the WebDAV lock database.

DAVLockDB /var/lib/dav/lockdb

</IfModule>

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

<Directory "/home/EMU/webmail/docs">

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

<IfModule mod_dav_fs.c>

# Location of the WebDAV lock database.

DAVLockDB /var/lib/dav/lockdb

</IfModule>

//設定CGI目錄的通路别名

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

//由于red hat中不使用worker MPM運作方式,是以不加載mod_cgid.c子產品

<IfModule mod_cgid.c>

#

# Additional to mod_cgid.c settings, mod_cgid has Scriptsock <path>

# for setting UNIX socket for communicating with cgid.

#

#Scriptsock logs/cgisock

</IfModule>

//設定CGI目錄的通路權限

<Directory "/var/www/cgi-bin">

AllowOverride None

Options None

Order allow,deny

Allow from all

</Directory>

//重定向連接配接

# Redirect permanent /foo http://www.example.com/bar

//設定自動生成目錄清單的顯示方式

//FancyIndexing 對每種類型的檔案前加上一個小圖示以示差別

//VersionSort 對同一個軟體的多個版本進行排序

//NameWidth=* 檔案名字段自動适應目前目錄下的最長檔案名

IndexOptions FancyIndexing VersionSort NameWidth=*

//當使用IndexOptions FancyIndexing之後,配置下面的參數

//用于告知伺服器在遇到不同的檔案類型或擴充名時采用MIME編碼格式

//辨識檔案類型并顯示相應的圖示

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*

AddIconByType (IMG,/icons/image2.gif) image/*

AddIconByType (SND,/icons/sound2.gif) audio/*

AddIconByType (VID,/icons/movie.gif) video/*

//當使用IndexOptions FancyIndexing之後,配置下面的參數

//用于告知伺服器在遇到不同的檔案類型或擴充名時采用所指定的格式

//并顯示相應的圖示

AddIcon /icons/binary.gif .bin .exe

AddIcon /icons/binhex.gif .hqx

AddIcon /icons/tar.gif .tar

AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv

AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip

AddIcon /icons/a.gif .ps .ai .eps

AddIcon /icons/layout.gif .html .shtml .htm .pdf

AddIcon /icons/text.gif .txt

AddIcon /icons/c.gif .c

AddIcon /icons/p.gif .pl .py

AddIcon /icons/f.gif .for

AddIcon /icons/dvi.gif .dvi

AddIcon /icons/uuencoded.gif .uu

AddIcon /icons/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^^

//當使用IndexOptions FancyIndexing之後,且無法識别檔案類型時

//顯示此處定義的圖示

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

//當伺服器自動列出目錄清單時,在所生成的頁面之後顯示readme.html的内容

ReadmeName README.html

//當伺服器自動列出目錄清單時,在所生成的頁面之前顯示header.html的内容

HeaderName HEADER.html

#

# IndexIgnore is a set of filenames which directory indexing should ignore

# and not include in the listing. Shell-style wildcarding is permitted.

#

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

//設定線上浏覽使用者可以實時解壓縮.z .gz .tgz類型的檔案

//并非所有浏覽器都支援

AddEncoding x-compress Z

AddEncoding x-gzip gz tgz

#

# DefaultLanguage nl

# Danish (da) - Dutch (nl) - English (en) - Estonian (et)

# French (fr) - German (de) - Greek-Modern (el)

# Italian (it) - Norwegian (no) - Norwegian Nynorsk (nn) - Korean (kr)

# Portugese (pt) - Luxembourgeois* (ltz)

# Spanish (es) - Swedish (sv) - Catalan (ca) - Czech(cz)

# Polish (pl) - Brazilian Portuguese (pt-br) - Japanese (ja)

# Russian (ru) - Croatian (hr)

#

//設定網頁内容的語言種類(浏覽器要啟用内容協商)

//對中文網頁,此項無實際意義

AddLanguage da .dk

AddLanguage nl .nl

AddLanguage en .en

AddLanguage et .et

AddLanguage fr .fr

AddLanguage de .de

AddLanguage he .he

AddLanguage el .el

AddLanguage it .it

AddLanguage ja .ja

AddLanguage pl .po

AddLanguage kr .kr

AddLanguage pt .pt

AddLanguage nn .nn

AddLanguage no .no

AddLanguage pt-br .pt-br

AddLanguage ltz .ltz

AddLanguage ca .ca

AddLanguage es .es

AddLanguage sv .se

AddLanguage cz .cz

AddLanguage ru .ru

AddLanguage tw .tw

AddLanguage zh-tw .tw

AddLanguage hr .hr

//當啟用内容協商時,設定語言的先後順序

LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv tw

//Prefer 當有多種語言可以比對時,使用LanguagePriority 清單的第一項

//Fallback 當沒有語言可以比對時,使用LanguagePriority 清單的第一項

ForceLanguagePriority Prefer Fallback

//設定預設字元集

AddDefaultCharset ISO-8859-1

//設定各種字元集

AddCharset ISO-8859-1 .iso8859-1 .latin1

AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen

AddCharset ISO-8859-3 .iso8859-3 .latin3

AddCharset ISO-8859-4 .iso8859-4 .latin4

AddCharset ISO-8859-5 .iso8859-5 .latin5 .cyr .iso-ru

AddCharset ISO-8859-6 .iso8859-6 .latin6 .arb

AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk

AddCharset ISO-8859-8 .iso8859-8 .latin8 .heb

AddCharset ISO-8859-9 .iso8859-9 .latin9 .trk

AddCharset ISO-2022-JP .iso2022-jp .jis

AddCharset ISO-2022-KR .iso2022-kr .kis

AddCharset ISO-2022-CN .iso2022-cn .cis

AddCharset Big5 .Big5 .big5

# For russian, more than one charset is used (depends on client, mostly):

AddCharset WINDOWS-1251 .cp-1251 .win-1251

AddCharset CP866 .cp866

AddCharset KOI8-r .koi8-r .koi8-ru

AddCharset KOI8-ru .koi8-uk .ua

AddCharset ISO-10646-UCS-2 .ucs2

AddCharset ISO-10646-UCS-4 .ucs4

AddCharset UTF-8 .utf8

# The set below does not map to a specific (iso) standard

# but works on a fairly wide range of browsers. Note that

# capitalization actually matters (it should not, but it

# does for some browsers).

#

# See ftp://ftp.isi.edu/in-notes...

# for a list of sorts. But browsers support few.

#

AddCharset GB2312 .gb2312 .gb

AddCharset utf-7 .utf7

AddCharset utf-8 .utf8

AddCharset big5 .big5 .b5

AddCharset EUC-TW .euc-tw

AddCharset EUC-JP .euc-jp

AddCharset EUC-KR .euc-kr

AddCharset shift_jis .sjis

//添加新的MIME類型(避免使用者編輯/etc/mime.types)

AddType application/x-tar .tgz

#

# AddHandler allows you to map certain file extensions to "handlers":

# actions unrelated to filetype. These can be either built into the server

# or added with the Action directive (see below)

#

# To use CGI scripts outside of ScriptAliased directories:

# (You will also need to add "ExecCGI" to the "Options" directive.)

#

#AddHandler cgi-script .cgi

#

# For files that include their own HTTP headers:

#

#AddHandler send-as-is asis

//設定apcche對某些擴充名的處理方式

AddHandler imap-file map

AddHandler type-map var

//使用過濾器執行SSI

AddOutputFilter INCLUDES .shtml

//設定錯誤頁面目錄的别名

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

<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_SERVICE_UNAVAILABLE.html.var

ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var

ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var

ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var

ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var

ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

</IfModule>

</IfModule>

繼續閱讀