Apache 安裝設定教學
實作版本下載點:http://apache.stu.edu.tw/httpd/binaries/win32/apache_2.0.55-win32-x86-no_ssl.msi
功能:功能強大、佔有率最高的 HTTP 伺服器軟體。
安裝步驟
- 下載並執行 apache_2.0.55-win32-x86-no_ssl.msi。
- 安裝精靈起始(Installation Wizard)畫面:
- 直接按 Next。
- 使用許可協議(License Agreement)畫面:
- 點選 I accept the terms in the license agreement。
- 按 Next。
- 讀我檔案(Read This First)畫面:
- 直接按 Next。
- 伺服器資訊設定(Server Information)畫面:
- Network Domain 與 Server Name 請依照實際情況填寫,若不知道可填 localhost。
- Administrator's Email Address 則是填自己的 Email 信箱。
- 按 Next。
- 安裝類型選擇(Setup Type)畫面:
- 點選 Custom。
- 按 Next。
- 自訂安裝元件選擇(Custom Setup)畫面:
- 直接按 Next。
- 安裝確認(Ready to Install the Program)畫面:
- 直接按 Install。
- 安裝完成(Installation Wizard Completed)畫面:
- 按 Finish。
- 安裝成功。
設定步驟
可將右下角小時鐘旁的Apache Monitor小圖示關閉,不影響伺服器運作。
httpd.conf 設定
用記事本開啟 C:\Program Files\Apache Group\Apache2\conf\httpd.conf,並按照以下原則進行修改。
請自行以關鍵字尋找並取代預設設定,若沒有預設設定則新增在檔案最後面即可。
強調的部分請依實際情況修改。
請注意斜線(/)與反斜線(\)的不同,以免造成不必要的錯誤。
設定完成後必須重新啟動伺服器以套用新的設定。
- 網頁目錄及權限設定
設定說明:
- 以 D:\www 目錄作為網頁存放路徑。
- 若目錄中沒有索引頁(index.html等),則傳回 403 Forbidden,不會列出目錄中檔案。
DocumentRoot "D:/www" <Directory /> Options None AllowOverride FileInfo Order allow,deny Allow from all </Directory>另外,建議以<Directory與</Directory>為關鍵字,搜尋並將不相關的目錄設定標記起來,使其沒有作用。
- 索引頁檔名設定
設定說明:
- 依次以index.html與index.xml為首頁檔名。
DirectoryIndex index.html index.xml - 錯誤頁面設定
設定說明:
- 在發生 403 Forbidden 與 404 Not Found 時,以 /error/*error.php 的內容取代錯誤訊息。
ErrorDocument 403 /error/403error.php ErrorDocument 404 /error/404error.php - 使用 mod_deflate 增進傳輸效能設定
設定說明:
- 在瀏覽器可以接受的情況下,傳送壓縮過的內容以增進傳輸效率,但會增加伺服器負擔。
- DeflateCompressionLevel 設定壓縮等級。
- AddOutputFilterByType 根據 MIME Type 設定要壓縮的檔案類型。
- AddOutputFilter 根據副檔名設定要壓縮的檔案類型。
LoadModule deflate_module modules/mod_deflate.so <ifmodule mod_deflate.c> DeflateCompressionLevel 9 AddOutputFilterByType DEFLATE text/html text/xml text/css application/x-httpd-php AddOutputFilter DEFLATE html htm xml php css </ifmodule>