# Listen
# 監聽端口, 例: Listen 80瀏覽器
# ServerRoot
# Apache 所在目錄, 例: ServerRoot "C:/Program Files/Apache Group/Apache2" (WINDOWS)服務器
# ServerAdmin
# 錯誤報告郵箱, 例: ServerAdmin btbtd@yahoo.com.cncookie
# DocumentRoot
# 站點根目錄, 例: DocumentRoot "I:/gi-2288"網絡
# DirectoryIndex
# 配置目錄索引文件,
# 例: DirectoryIndex index.php index.php3 index.html index.htmapp
# ServerName
# 服務器域名/IP地址, 例: ServerName gi.2288.orgide
# DefaultLanguage
# 爲全部指令做用域範圍內的文件設定某一特定的缺省語言
# 語法: DefaultLanguage MIME-lang, 例: DefaultLanguage zh-CN工具
# AddDefaultCharset
# 在沒有進行指定字符集的狀況下向迴應中加入的默認字符集, 默認值: AddDefaultCharset Off
# 例: AddDefaultCharset utf-8, 語法: 語法: AddDefaultCharset On|Off|字符集
# AddHandler
# 在文件擴展名與特定的處理器間創建映射, 例: AddHandler cgi-script .cgi .pl
# 語法: AddHandler handler-name extension
# AccessFileName
# 定義配置文件, 例: AccessFileName .htaccess
# 當向客戶端返回文檔時,若是設置了此目錄的發佈配置文件功能。
# 服務器將在這個文檔的各個路徑中從名字列表中查找第一個存在的配置文件。
# Timeout
# 超時時間, 例: Timeout 300
# TypesConfig
# 指定mime.types文件的位置, 默認: TypesConfig conf/mime.types
# DefaultType
# DefaultType MIME類型,
# 有時會發生這樣的事:服務器會被要求提供一個文檔,而這個文檔的類型沒法由它的MIME類型映射所決定。
# 服務器必須通知客戶端其文檔的內容類型。
# 因此當一個未知類型出現時,將會使用DefaultType。
# 例: DefaultType image/gif
# HostnameLookups
# 啓用對客戶端IP的DNS查找, 語法: HostnameLookups on|off|double
# ErrorLog
# 定位服務器存放錯誤日誌的位置, 例: ErrorLog "G:/Apache/dummy-gi.2288.org.80-error_log"
# LogLevel
# 控制錯誤日誌的級別, 默認值: LogLevel warn
# emerg 緊急 - 系統沒法使用。
# alert 必須當即採起措施。
# crit 致命狀況。
# error 錯誤狀況。
# warn 警告狀況。
# notice 通常重要狀況。
# info 普通訊息。
# debug 出錯級別信息
# CustomLog
# 設定日誌的文件名和格式, 默認: CustomLog logs/access.log common
# ServerTokens
# 配置服務器HTTP迴應頭, 默認: ServerTokens Full
# ServerTokens Prod[uctOnly], 服務器會發送(好比說):Server:Apache
# ServerTokens Major, 服務器會發送(好比說):Server:Apache/2
# ServerTokens Minor, 服務器會發送(好比說):Server:Apache/2.0
# ServerTokens Min[imal], 服務器會發送(好比說):Server:Apache/2.0.41
# ServerTokens OS, 服務器會發送(好比說):Server: Apache/2.0.41 (Unix)
# ServerTokens Full (or not specified),
# 服務器會發送(好比說):Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2
# MaxSpareServers
# 設置apache的最大空閒進程數
# 語法: MaxSpareServers number
# 默認: MaxSpareServers 100
# 例: MaxSpareServers 1000
# MaxKeepAliveRequests
# 設置每一個鏈接的最大請求數
# 語法: MaxKeepAliveRequests number
# 默認值: MaxKeepAliveRequests 100
# ServerSignature
# 配置服務器生成頁面的頁腳, 默認值: ServerSignature Off
# 語法: ServerSignature On|Off|EMail
# 應用:
# Listen 80
# ServerRoot "C:/Program Files/Apache Group/Apache2"
# ServerAdmin btbtd@yahoo.com.cn
# DocumentRoot "I:/gi-2288"
# DirectoryIndex index.php index.php3 index.html index.htm
# ServerName gi.2288.org
# DefaultLanguage zh-CN
# AddDefaultCharset utf-8
# AddDefaultCharset Off
# AddHandler cgi-script .cgi .pl
# AccessFileName .htaccess
# Timeout 300
# TypesConfig conf/mime.types
# ErrorLog "G:/Apache/dummy-gi.2288.org.80-error_log"
# LogLevel warn
# CustomLog logs/access.log common
# ServerTokens Prod[uctOnly]
# ServerSignature Off
########02. <VirtualHost *:80> 虛擬主機
# Listen 80
# 設定監聽端口
# NameVirtualHost 192.168.1.2:80
# 名字/端口型 虛擬主機
# <VirtualHost *:88>
# </VirtualHost>
# 虛擬主機段
# ServerAdmin btbtd@yahoo.com.cn
# 聯繫管理會用的信箱
# DocumentRoot "I:/gi-2288"
# 站點根目錄
# ServerName gi.2288.org
# 域名
# ErrorLog "G:/Apache/dummy-gi.2288.org.80-error_log"
# 錯誤日誌 # 日誌記錄是好東西,注意查看日誌記錄
# ------------以上是虛擬主機內容
# 完整應用:
# Listen 80
# NameVirtualHost 192.168.1.2:80
# <VirtualHost *:88>
# ServerAdmin btbtd@yahoo.com.cn
# DocumentRoot "I:/gi-2288"
# ServerName gi.2288.org
# </VirtualHost>
########03. <Directory> + Alias
# 語法: <Directory 目錄路徑> ... </Directory>
# 封裝一組指令,使之僅對具備某個名字的文件系統目錄及其子目錄起做用。
# 不容許目錄瀏覽, 例:
# Alias /document "J:/Document/"
# <Directory "J:/Document/">
# Options FollowSymLinks
# AllowOverride none
# Order allow,deny
# Allow from all
# </Directory>
# 容許目錄瀏覽, 例:
# Alias /document "J:/Document/"
# <Directory "J:/Document/">
# Options Indexes
# AllowOverride none
# Order allow,deny
# Allow from all
# </Directory>
# Allow & Deny
# Allow和Deny指令能夠容許或拒絕來自特定主機名或主機地址的訪問,
# 同時,Order指令告訴Apache處理這兩個指令的順序, 以改變過濾器。
# Allow
# 容許全部地址的訪問, 例: Allow from all
# 只容許特定IP地址訪問目錄, 例: Allow from 205.252.46.165
# 只容許特定域名地址訪問目錄, 例: Allow from www.google.com
# 只容許特定IP 段訪問, 例: Allow from 10.10.10.0/255.255.0.0
# Deny
# 拒絕全部地址訪問目錄, 例: Deny from all
# 拒絕特定域名訪問目錄, 例: Deny from www.google.com
# 拒絕特定IP訪問目錄, 例: Deny from 218.15.84.152
# 拒絕某個IP段訪問目錄, 例: Deny from 10.10.10.0/255.255.0.0
# Allow & Deny 混合使用
# 拒絕全部地址的訪問, 但接受 Google 的訪問, 例:
# <Directory "J:/Document/">
# Options FollowSymLinks
# Order Deny, Allow
# Deny from all
# Allow from www.google.com
# </Directory>
# 接受全部地址的訪問, 但拒絕 Google 的訪問, 例:
# <Directory "J:/Document/">
# Options FollowSymLinks
# Order Deny, Allow
# Deny from www.google.com
# Allow from all
# </Directory>
# Options
# 語法: Options [+|-]可選項 [[+|-]可選項] ...
# 配置在特定目錄使用哪些特性,
# Options指令控制了在特定目錄中將使用哪些服務器特性。
# 可選項能設置爲None,在這種狀況下,將不啓用任何額外特性。
# 或設置爲如下選項中的一個或多個:
# All, 除MultiViews以外的全部特性。這是默認設置。
# ExecCGI, 容許執行CGI腳本.
# FollowSymLinks, 服務器會在此目錄中使用符號鏈接。
# 注意:即使服務器會使用符號鏈接,但它不會改變用於匹配<Directory>配置段的路徑名。
# 注意:若是此配置位於<Location>配置段中,則此設置會被忽略。
# Includes, 容許服務器端包含。
# IncludesNOEXEC,容許服務器端包含,但禁用#exec命令和#exec CGI。
# 但仍能夠從ScriptAliase目錄使用#include 虛擬CGI腳本。
# Indexes, 若是一個映射到目錄的URL被請求,
# 而此目錄中又沒有DirectoryIndex(例如:index.html.zh-cn.gb2312),
# 那麼服務器會返回一個格式化後的目錄列表。
# MultiViews,容許內容協商的多重視圖。
# SymLinksIfOwnerMatch, 服務器僅在符號鏈接與其目的目錄或文件擁有者具備一樣的用戶id時才使用它。
# 注意:若是此配置出如今<Location>配置段中,此選項將被忽略。
# AllowOverride
# 語法: AllowOverride All|None|指令類型 [指令類型] ...
# 說明: 容許存在於.htaccess文件中的指令類型
# 當服務器發現了一個.htaccess文件(由AccessFileName指定)時,
# 它須要知道在這個文件中聲明的哪些指令能覆蓋在此以前指定的訪問信息。
# AllowOverride僅在<Directory>小節中才是有效的。在<Location>或<Files>小節中都是無效的。
# 若是此指令設置爲None,那麼.htaccess文件將被徹底忽略。
# 在這種狀況下,服務器甚至都不會試着從文件系統讀取.htaccess文件。
# 當此指令設置爲All時,全部具備.htaccess 上下文的指令都容許出如今.htaccess文件中。
# 提示:容許使用 .htaccess 文件將會致使服務器性能的降低。
# 另外,每次請求一個頁面時,都須要讀取.htaccess文件。
# 開啓 .htaccess 支持必須 這樣設置 AllowOverride all, 例:
# Alias /v "J:/pwd/"
# <Directory "J:/pwd/">
# Options Indexes
# AllowOverride all
# Order allow,deny
# Allow from all
# </Directory>
# 若是網絡站點上有些敏感信息或只但願爲一個小羣體所訪問,
# 這裏介紹幾個方法確保使用戶只能訪問容許被訪問的資源。
# 一般在 <Directory> 段或針對單個目錄的配置文件(.htaccess files)。
# 若是但願使用 .htaccess 文件, 則必須設置服務器以容許在這些文件中使用認證指令,
# 即,用 AllowOverride 指令 指定哪些指令在針對單個目錄的配置文件中有效。
# 用密碼來保護服務器上的目錄, 首先須要創建一個密碼文件。
# 這個文件能夠放在不能被網絡訪問的位置,以免被下載,
# 例如: G:/Apache 之外的空間不能被網絡訪問,
# 那麼能夠考慮把密碼文件放在 G:/Apached 目錄中。
# Apache在其安裝目錄的 bin 子目錄中提供了叫 htpasswd 的工具,
# 以創建密碼文件,能夠這樣使用:
# (先切換到Apache 安裝目錄, 例: C:/Program Files/Apache Group/Apache2/bin)
# 在命令行輸入: htpasswd -c G:/Apache/passwords E
# (這樣就創建了一個用戶 E, 具體按本身須要設置用戶和密碼)
# 接着會要求你輸入密碼, 而後再輸入一次,檢驗密碼.
# 這樣在 G:/Apache/ 就多了一個 passwords 文件(沒有後綴名)
# Windows 下的話會用 MD5 加密密碼.
# 而後在要 設置權限的目錄裏創建一個 .htaccess 文件,
# .htaccess 文件的內容是:
# AuthType Basic
# AuthName "Restricted Files"
# AuthUserFile G:/Apache/passwords
# Require user E
# 演示頁面: http://gi.2288.org:88/v
# 用戶: E 密碼:testhtpasswd
# 注: 目錄必須容許 AllowOverride all ,這樣 .htaccess 文件才能生效.
# Apache 的日誌文件能夠提供很是多的信息, 頗有必要了解這些日誌
# C:/Program Files/Apache Group/Apache2/logs (Windows 中的日誌文件存放處)
# access.log(訪問日誌,瞭解客戶端所訪問的內容) & error.log(錯誤日誌)
# 自定義日誌格式
# mod_log_config
# 狀態: Base
# 說明: 將對服務器發起的請求記錄到日誌
# 默認: CustomLog logs/access.log common
# 推薦設置:
# CustomLog logs/access_log "%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i""
# LogFormat
# 默認值: LogFormat "%h %l %u %t /"%r/" %>s %b"
# 語法: LogFormat format|nickname [nickname]
# 說明: 定義日誌文件裏的記錄格式
# 例: LogFormat "%v %h %l %u %t /"%r/" %>s %b" vhost_common
# CustomLog
# 狀態: Base
# 語法: CustomLog file|pipe format|nickname [env=[!]environment-variable]
# 說明: 設定日誌的文件名和格式
# 例: CustomLog logs/access_log "%h %l %u %t /"%r/" %>s %b"
# ErrorLog
# 語法: ErrorLog 文件路徑|syslog[:facility]
# 默認值: ErrorLog logs/error_log (Unix) ErrorLog logs/error.log (Windows and OS/2)
# 說明: 定位服務器存放錯誤日誌的位置
# 例: ErrorLog "G:/Apache/dummy-gi.2288.org.88-error_log"
# CookieLog
# 語法: CookieLog filename
# 說明: 設定針對cookies的日誌文件名
# 模塊: mod_log_config
# RewriteLog
# 語法: RewriteLog file-path
# 說明: 設置重寫引擎日誌的文件名
# 模塊: mod_rewrite
# 例: RewriteLog "/usr/local/var/apache/logs/rewrite.log" (Unix/Linux)
# RewriteLog "G:/Apache/rewrite.log" (Windows)
# 一些常見的格式串以下所示:
# 能用日誌格式(CLF): "%h %l %u %t /"%r/" %>s %b"
# 帶虛擬主機的通用日誌格式: "%v %h %l %u %t /"%r/" %>s %b"
# NCSA擴展/組合日誌格式: "%h %l %u %t /"%r/" %>s %b /"%{Referer}i/" /"%{User-agent}i/""
# Referer日誌格式: "%{Referer}i -> %U"
# Agent (Browser)日誌格式: "%{User-agent}i"
# 注意:根據你的服務器配置,可能有必要對例子做些微修改,
# 好比,新啓用 mod_alias 和 mod_userdir 時要增長[PT]標誌,
# 或者重寫 .htaccess 而不是單個服務器中的規則集。
# 對一個特定的規則集應該首先去理解然後再去用以免出問題。
# 重寫語法
# RewriteEngine on
# RewriteRule ^/$ /www/ [R]
# 通常重寫方法
# 重寫頁面:http://gi.2288.org:88/modules/news/index.php
# RewriteRule /modules/news/index.htm$ /modules/news/index.php
# 完成頁面: http://gi.2288.org:88/modules/news/index.htm
# 重寫頁面: http://gi.2288.org:88/modules/news/index.php?storytopic=2
# RewriteRule /modules/news/topic_(.*)/.htm$ /modules/news/index.php?storytopic=$1
# 完成頁面: http://gi.2288.org:88/modules/news/topic_2.htm
# 重寫頁面:http://gi.2288.org:88/index.php?storytopic=2start=10
# RewriteRule /topic(.*)-(.*)/.htm$ /index.php?storytopic=$1&start=$2
# 完成頁面: http://gi.2288.org:88/topic2-2.htm
# 注: 每增長一個重寫ID,必須累加$1
# 好比頁面: http://gi.2288.org:88/ct=2x=10y=20
# 能夠這樣重寫:
# RewriteRule /ct(.*)-(.*)-(.*)/.htm$ /ct=$1x=$2y=$3
# 效果: http://gi.2288.org:88/ct2-10-20.htm
# 移動宿主目錄到不一樣的網站服務器
# 說明:
# 一般,許多網管在創建一個新的網站服務器時,都會有這樣的要求:
# 重定向一個網站服務器上的全部宿主目錄到另外一個網站服務器
# 方案:
# 很簡單,用mod_rewrite。在老的網站服務器上重定向全部的URL
# /~user/anypath到http://newserver/~user/anypath。
# RewriteEngine on
# RewriteRule ^/~(.+) http://newserver/~$1 [R,L]
# 依賴於瀏覽器的內容
# 說明:
# 至少對重要的頂級頁面,有時候有必要提供依賴於瀏覽器的最佳的內容,
# 即對最新的Netscape提供最大化的版本,對Lynx提供最小化的版本,
# 而對其餘的瀏覽器則提供一個功能通常的版本。
# 方案:
# 對此,內容協商無能爲力,由於瀏覽器不提供其那種形式的類型,
# 因此只能在HTTP頭"User-Agent"上想辦法。
# 如下規則集能夠完成這個操做:
# 若是HTTP頭"User-Agent"以"Mozilla/3"開頭,
# 則頁面foo.html 被重寫爲foo.NS.html ,然後重寫操做終止;
# 若是是"Lynx"或者版本號爲1和2的"Mozilla",則重寫爲foo.20.html ;
# 而其餘全部的瀏覽器收到的頁面則是foo.32.html :
# RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
# RewriteRule ^foo/.html$ foo.NS [L]
# RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
# RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
# RewriteRule ^foo/ $ foo.20 [L]
# RewriteRule ^foo/ $ foo.32 [L]
# 阻止Robots
# 說明:
# 如何阻止一個徹底匿名的robot取得特定網絡區域的頁面?
# 一個/robots.txt文件能夠包含若干"Robot Exclusion Protocol(robot排除協議)"的行,
# 但不足以阻止此類robot。
# 方案:
# 能夠用一個規則集以拒絕對網絡區域/~quux/foo/arc/
# (對一個很深的目錄區域進行列表可能會使服務器產生很大的負載)的訪問。
# 還必須確保僅阻止特定的robot,就是說,僅僅阻止robot訪問主機是不夠的,
# 這樣會同時也阻止了用戶訪問該主機。爲此,就須要對HTTP頭的User-Agent信息做匹配。
# RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*
# RewriteCond %{REMOTE_ADDR} ^123/.45/.67/.[8-9]$
# RewriteRule ^/~quux/foo/arc/.+ - [F]
# 防止盜鏈圖片
# 說明:
# 假設,http://gi.2288.org:88/myalbum/有一些內嵌圖片的頁面,
# 這些圖片很好,因此就有人用超鏈連到他們本身的頁面中了。
# 因爲這樣徒然增長了咱們的服務器的流量,所以,咱們不肯意這種事情發生。
# 方案:
# 雖然,咱們不能100%地保護這些圖片不被寫入別人的頁面,
# 但至少能夠對發出HTTP Referer頭的瀏覽器加以限制。
# RewriteCond %{HTTP_REFERER} !^$
# RewriteCond %{HTTP_REFERER} !^http://gi.2288.org:88/myalbum/.*$ [NC]
# RewriteRule .*/.gif$ - [F]
# RewriteCond %{HTTP_REFERER} !^$
# RewriteCond %{HTTP_REFERER} !.*/foo-with-gif/.html$
# RewriteRule ^inlined-in-foo/.gif$ - [F]
# 禁止盜鏈
# SetEnvIfNoCase Referer "^http://gi.2288.org:88/" local_ref=1
# <FilesMatch ".(gif|jpg|png|jpeg|zip|rar|exe|swf|txt)">
# Order Allow,Deny
# Allow from env=local_ref
# </FilesMatch>
# 加載 PHP 5
# LoadModule php5_module c:/php/php5apache2.dll
# #AddModule mod_php4.c
# AddType application/x-httpd-php .php
# ScriptAlias /php/ "c:/php/"
# AddType application/x-httpd-php .php
# Action application/x-httpd-php "/php/php-cgi.exe"
# 以服務方式運行Apache for Windows
# 你能夠像下面這樣將Apache安裝爲Windows NT服務:apache -i -n "服務名"
# 要安裝一個使用特定配置的服務,安裝時指定配置文件:
# apache -i -n "服務名" -f "/my server/conf/my.conf"
# 要移除一個Apache服務,使用: apache -u -n "服務名"
# 注: 若是沒有指定服務名,缺省地,將使用"Apache"。
# 一旦服務被安裝,你可使用-n選項和其餘選項一塊兒訪問該服務的配置文件。
# 例如:測試一個服務的配置文件:apache -n "服務名" -t
# 啓動一個使用某服務配置文件的控制檯Apache:apache -n "服務名"
# 控制服務方式的Apache
# 啓動、重啓及關閉/中止Apache服務:
# apache -n "服務名" -k start
# apache -n "服務名" -k restart
# apache -n "服務名" -k shutdown
# apache -n "服務名" -k stop
# 或使用NT本機命令NET來啓動和中止Apache服務,像這樣:# NET START "服務名" # NET STOP "服務名"