Apache 的設定

在用 pkg_add 安裝好 Apache 後, 基本上這已經是一個可以直接使用的 web server 了, 不過如果能稍微地調整一下會更方便使用. Apache 的設定檔是在 /usr/local/etc/apache/httpd.conf, 以下是一些比較可能需要會修改的地方

1. 在一些系統自動產生的網頁會指出這個網站的維護管理人員是誰, 其實是參考ServerAdmin 這個設定, 請把它改成您網站負責人員的 Emain Address,

原本的設定
ServerAdmin you@your.address
更改後的設定
ServerAdmin wwwadm@turtle.ee.ncku.edu.tw

2. httpd.conf 利用
<Directory 目錄路徑>
......
<Directory />
的方式來設定存放網頁的目錄能夠具有哪些功能

2.a.首先我們修改的是對所有網頁目錄的內定設定值, 原本的設定
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

更改後的設定
<Directory />
    Options FollowSymLinks Indexes
    AllowOverride AuthConfig Limit
</Directory>

Options Indexes 是讓網頁目錄如果沒有 index.html 這個檔案時, 能夠由系統自動將裡頭的檔案列表顯示出來給使用者
AllowOverride AuthConfig  Limit 是指讓每個網頁目錄能夠依自己的需求來設定一些密碼保護或是存取權限之類的限制

關於如何替網頁設定密碼保護或是存取權限, 請參考 http://turtle.ee.ncku.edu.tw/~tung/cgi/htaccess.html


2.b 接著修改關於系統網頁目錄的設定值.
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/www/data">
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
    Options Indexes FollowSymLinks
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
    AllowOverride None               <---修改成 AllowOverride AuthConfig Limit
#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all
</Directory>

3. 當 Apache 收到一個 URL 時, 如果這個 URL 是指向一個目錄, Apache server 會將這個目錄的 index.html 當作網頁進入點, 將其內容顯示出來給使用者, 不過除了 index.html 外, 我們還可以指定其他的檔案也可以當作網頁進入點

原本的設定
DirectoryIndex index.html
更改後的設定
DirectoryIndex index.html index.htm

這樣在找不到 index.html 這個檔時, apache 會去找找看有沒有 index.htm, 如果有就當作網頁進入點

在作完上述的設定修改後, Web Server 以經可以跑得很不錯了, 當然 httpd.conf 中還有很多其他的設定, 不過大多數在 httpd.conf 中就有詳細的說明, 如果還是有不了解的地方, 在
/usr/local/share/doc/apache 內有詳細的文件可以參考


我的httpd.conf setting