廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 13857 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
johnroyer 手機
個人頭像
個人文章 個人相簿 個人日記 個人地圖
特殊貢獻獎
小有名氣
級別: 小有名氣 該用戶目前不上站
推文 x8 鮮花 x505
分享: 轉寄此文章 Facebook Plurk Twitter 版主評分版主評分 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[FreeBSD][發表] Apache Virtual Host
精華文章
多注意的話
可以發現有些網址非常特別

google.com...
mail.google.com
picasaweb.google.com


而且 ping 一下還會發現這些 DomainName 都連到同一個 IP
這就是 Apache Virtual Host 的功能啦
當然 Google 不是這樣做的啦………舉例而已

要啟動 Apache 的 Virtual Host 功能
首先開啟 /usr/local/etc/apache22/httpd.conf
在任意地方加入以下設定

複製程式
# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf

由上面的設定可以看出
這一段會使 Apache 去讀取 extra/httpd-vhosts.conf
而 httpd-vhosts.conf 就是 Virtual Host 的設定檔

當然也可以直接寫在 http.conf 內
但是為了方便管理以及日後的維護
通常都會放在 extra/httpd-vhosts.conf


接下來看看 httpd-vhosts.conf 裡面寫了些什麼

複製程式
# Virtual Hosts
#
# 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:[url]http://httpd.apache.org/docs/2.2/vhosts/>[/url]
# 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.
#
NameVirtualHost *:80

 VirtualHost example:
 Almost any Apache directive may go into a VirtualHost container.
 The first VirtualHost section is used for all requests that do not
 match a ServerName or ServerAlias in any <VirtualHost> block.

<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host.example.com[/email]
    DocumentRoot /www/docs/dummy-host.example.com
    ServerName dummy-host.example.com
    ServerAlias [url]www.dummy-host.example.com[/url]
    ErrorLog /var/log/dummy-host.example.com-error_log
    CustomLog /var/log/dummy-host.example.com-access_log common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
    DocumentRoot /www/docs/dummy-host2.example.com
    ServerName dummy-host2.example.com
    ErrorLog /var/log/dummy-host2.example.com-error_log
    CustomLog /var/log/dummy-host2.example.com-access_log common
</VirtualHost>

可以看出每個不同的 vhost 都被包在標籤中
<VirtualHost *:80>
......
</VirtualHost>

參數說明:
ServerAdmin:此 vhost 的管理員電子郵件
DocumentRoot:連結到此 vhost 時,會以哪個目錄當作預設的根目錄
ServerName:vhost 的 DNS
ServerAlias:vhost 的 Alias
ErrorLog:對於這個 vhost 錯誤記錄檔的儲存位置
CustomLog:對於這個 vhost 記錄檔的儲存位置

設定好之後
別忘記將原本做為參考用的二個 vhost 刪除或設為註解
然後重新啟動 appachectl restart

//----------------------------------------------------------------

再補上一招管理密技
用的方法一樣是「include」
你把的所有 vhost 設定分別儲存成檔案存放在其他目錄

複製程式
NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin [email]mail@mail.com[/email]
        DocumentRoot /usr/local/www/apache22/data/
        ServerName 192.168.0.1
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>

Include /usr/local/etc/apache22/vhosts/*.conf

然後其他的設定檔分別儲存到 /usr/local/etc/apache22/vhosts/
檔名為 vhost1.mychat.com.conf
    vhost2.mychat.com.conf



vhost1.mychat.com.conf:
複製程式
<VirtualHost *:80>
        ServerAdmin [email]mail1@mychat.com[/email]
        DocumentRoot /usr/local/www/apache22/data/vhost1/
        ServerName vhost1.mychat.com.conf
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/vhost1/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>





vhost2.mychat.com.conf
複製程式
<VirtualHost *:80>
        ServerAdmin [email]mail2@mychat.com[/email]
        DocumentRoot /usr/local/www/apache22/data/vhost2/
        ServerName vhost2.mychat.com.conf
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/vhost2/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>


這樣管理上會方便許多

原文:Zeroplex 生活隨筆: FreeBSD Apache Virtual Host
http://zeroplex.blogspot.com/2008/05/...irtual-host.html

請多指教


[ 此文章被johnroyer在2008-08-18 03:13重新編輯 ]

此文章被評分,最近評分記錄
財富:250 (by andyz)



My Blog : Zeroplex
Plurk : Zeroplex
獻花 x0 回到頂端 [樓 主] From: | Posted:2006-10-17 02:20 |
singulai
數位造型
個人文章 個人相簿 個人日記 個人地圖
路人甲
級別: 路人甲 該用戶目前不上站
推文 x0 鮮花 x0
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

解說清楚,實做簡單,感謝。


獻花 x0 回到頂端 [1 樓] From:未知地址 | Posted:2008-09-01 11:02 |
mnbmnb5266
個人文章 個人相簿 個人日記 個人地圖
小有名氣
級別: 小有名氣 該用戶目前不上站
推文 x5 鮮花 x46
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

謝謝大大的程式分享,先看看管不管用再說


我的收藏
https://pan.baidu.com/s/1QUJ9lr_VzxXKRJAlBJgUQA
提取码:am2c
獻花 x0 回到頂端 [2 樓] From:加拿大Rogers | Posted:2010-08-21 22:40 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.024897 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言