天天看點

Ubuntu Server 之Apache2 虛拟主機配置指南(個人實踐解讀)

          這是完成在ubuntu server的apache伺服器上安裝一個虛拟主機的具體配置。希望對用到的朋友有所幫助。

ps:推薦使用vim編輯器編輯文檔,友善快捷;

        以下文段來自/etc/apache2/sites-available/dgd.server2010.com(最後的檔案名為虛拟主機的檔案名,可以自定義)

# 檔案開始

<virtualhost *:80>

# 使用“*”的意思是監聽所有的ip位址的80端口。<virtualhost *.80>的意思是開始一個虛拟主機的配置,在同一個檔案中可以有多個虛拟主機的設定。當然我們不推薦在一個檔案中設定多個虛拟主機。

# 注意:一行中不能有空格,否則換行符無效。

    serveradmin [email protected]

# 管理者郵箱

# 注意:注釋符前面不能有空格。

    servername dgd.server2010.com

#主機名,這裡很重要,該名稱要和前面設定的主機名稱一緻。

    documentroot /home/pp/webserver/

#網站檔案的根目錄,重要目錄,放置使用者網頁内容。

#建議不要用設有權限的使用者的目錄内的目錄建立站點。比如說在安裝伺服器時将/home/使用者名/這個檔案夾進行加密,或這設為個人。

#如果設有,那麼請将使用者目錄的權限配置設定給others,即其他使用者

    <directory />

        options followsymlinks

        allowoverride none

    </directory>

    <directory /home/pp/webserver/>

#使用者目錄的相關權限,目錄名與網站根目錄相一緻。

        options indexes followsymlinks multiviews

        order allow,deny

        allow from all

    scriptalias /cgi-bin/ /usr/lib/cgi-bin/

#cgi腳本位置

    <directory "/usr/lib/cgi-bin/">

#cgi腳本權限

        options +execcgi -multiviews +symlinksifownermatch

    errorlog ${apache_log_dir}/error.log

#錯誤日志位置

    # possible values include: debug, info, notice, warn, error, crit,

    # alert, emerg.

    loglevel warn

    customlog ${apache_log_dir}/access.log combined

    alias /doc/ "/usr/share/doc/"

#網站文檔位置

    <directory "/usr/share/doc/">

        options indexes multiviews followsymlinks

        allowoverride none

        order deny,allow

        deny from all

        allow from 127.0.0.0/255.0.0.0 ::1/128

</virtualhost>

#完成虛拟主機的配置