Virtual Host 最簡單的做法 (含 DNS,讓你建目錄等於建虛擬主機)
from :
http://www.sinsen.com.tw/callboard/schoolboard.php3?do=read_msg&board=school_board&msg_id=237&order=desc&cur_page=1
以下有部份取自原來我貼在 VBird 的文章
Apache 的 VH 其實設法相當多種,
相信大多數都是這種設法
DocumentRoot /home/httpd/html/enum
ServerName VH1.xxx.com.tw
ErrorLog logs/VH1-error.log
CustomLog logs/VH2-access_log common
因為書本上教的,但是你改了這些值, httpd 要重新啟動...
高明點用 rewrite modules: (要有 RE 的基礎)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.[^.]+.host.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www.([^.]+).host.com(.*) /home/$1$2
這樣只要新增 /home 目錄下的目錄就是新增 VirtualHost 了,且 httpd 不需重開
(有很多不同設法, http://httpd.apache.org/docs/misc/rewriteguide.html)
另外一種方法:Mass Virtual Hosting (亦不需要重啟 httpd)
UseCanonicalName on
CustomLog /home/www/access_log "%{VHOST}e %h %l %u %t "%r" %>s %b" :
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/etc/vhost.map #路徑自己設
RewriteCond %{REQUEST_URI} !^/commonurl1/.*
RewriteCond %{REQUEST_URI} !^/commonurl2/.*
RewriteCond %{REQUEST_URI} !^/commonurlN/.*
RewriteCond %{HTTP_HOST} !^$
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
#/etc/vhost.map 檔,加一行並新增對應目錄就是一個 VirtualHost
www1.xxx.com.tw:80 /home/www/www1
www2.xxx.com.tw:80 /home/www/www2
#這個方法也是 rewrite 的一種,且亦不需重新啟動 httpd,但是 httpd.conf 中要
#enable 這兩行 或是 complier 時以 static link 方式編進 httpd core
# rewrite 雖不容易懂,但懂了後就很好用
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
最後一種方法最簡單:
UseCanonicalName Off
VirtualDocumentRoot /home/www/%0
#%0 就是 HOST_NAME,像 www.xxx.com.tw ,一個目錄就是一個 Virtual,
#詳細用法可以看這裏哦
# http://httpd.apache.org/docs-2.1/mod/mod_vhost_alias.html
%N 的意義
0 the whole name
1 the first part
2 the second part
-1 the last part
-2 the penultimate part
2+ the second and all subsequent parts
-2+ the penultimate and all preceding parts
1+ and -1+ the same as 0
通常若您做網站代管這種業務,目錄都會再依序分層,有學過資料結構和演算法的話,你就知道一個平的目錄,不如一個有深度規畫的目錄來的好:
/home/www/tw/com/xxx/
/home/www/tw/org/yyy/
那就是
VirtualDocumentRoot /home/www/....你自己去實驗了哦...
以上是 VH 的設定法,我們假設 IP 為 1.2.3.80, 那我們再來看看 dns 的部份
$TTL 3600
$ORIGIN xxx.com.tw.
@ IN SOA dummy.xxx.com.tw. admin.xxx.com.tw. (
1 38400 3600 864000 86400)
IN NS ns1
IN NS ns2
IN MX 10 mail
ns1 IN A 1.2.3.4
ns2 IN A 1.2.3.5
mail IN A 1.2.3.4
www IN A 1.2.3.80
; 以上都是一般的設定狀況...最後再加一筆
* IN A 1.2.3.80
這樣的 zone file 的內容,只要是查 除了 ns1/ns2/mail/www 外,
查 a.xxx.com.tw 或 xxxxxxxxxx.xxx.com.tw 得到的結果都是
1.2.3.80, 這也是大家習慣的萬用字元的用法
我們依據以下設法(httpd.conf):
UseCanonicalName Off
VirtualDocumentRoot /home/www/%0
在 /home/www/ 之下, 你每建一個 ???.xxx.com.tw 的目錄
(不含巳指明且不同 IP 的),就是建立一個 虛擬主機哦
EZ 吧 ~~我自己幾乎都是用這樣的做法,至少較最多人用的方法
都簡單許多哦
---------
參考網址:
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/ic2924/info/rzaie/rzaiemod_vhost_alias.htm
ugg boots
christian louboutin
louboutin
lv bags
louis vuitton handbags
louis vuitton
lv handbags
mbt shoes
christian louboutin
chanel bags
cheap chanel bags
discount chanel bags
chanel bags sale
christian louboutin
cheap christian louboutin
discount christian louboutin
christian louboutin sale
gucci bags
cheap gucci bags
discount gucci bags
gucci bags sale
dg bags
cheap dg bags
discount dg bags
dg bags sale
dior bags
cheap dior bags
discount dior bags
dior bags sale
coach bags
cheap coach bags
discount coach bags
coach bags sale
chloe bags
cheap chloe bags
discount chloe bags
chloe bags sale
prada bags
cheap prada bags
discount prada bags
prada bags sale
fendi bags
cheap fendi bags
discount fendi bags
fendi bags sale
hermes bags
cheap hermes bags
discount hermes bags
hermes bags sale
miu miu bags
cheap miu miu bags
discount miu miu bags
miu miu bags sale
marc jacobs bags
cheap marc jacobs bags
discount marc jacobs bags
marc jacobs bags sale
marni bags
cheap marni bags
discount marni bags
marni bags sale
loewe bags
cheap loewe bags
discount loewe bags
loewe bags sale