歡迎您光臨本站 註冊首頁

linux下apache配置文件詳解

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

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


[火星人 ] linux下apache配置文件詳解已經有502次圍觀

http://coctec.com/docs/linux/show-post-51351.html