如果,想實(shí)現多個(gè)域名訪(fǎng)問(wèn)同一個(gè)網(wǎng)站時(shí),可以使用ServerAlias來(lái)實(shí)現:
[b]前提條件:[/b]
已在域名服務(wù)提供商處或自己管理的DNS服務(wù)器上,將多個(gè)域名或A記錄(如:test.com 、[url]www.test.com[/url] 、pub.test.com )指向同一個(gè)公網(wǎng)IP(如:166.166.166.166)
[b]此例中,Apache中涉及到的相關(guān)選項說(shuō)明:[/b]
NameVirtualHost * (設定虛擬主機的ip)
<VirtualHost *> (開(kāi)頭設定虛擬主機的ip)
ServerAdmin [email]admin@domain.com[/email] (設定虛擬主機的管理者信箱,不用和預設的網(wǎng)站管理者相同)
DocumentRoot /yourdir (指定虛擬主機的網(wǎng)站主目錄)
ServerName domain.com (設定虛擬主機的名稱(chēng),指定設定虛擬主機的UR)
ServerAlias [url]www.domain.com[/url] (設定虛擬主機的?名,例: WWW )
ErrorLog logs/?? ?? (虛擬主機發(fā)生錯誤時(shí)要記錄在哪個(gè)目錄,可不設.)
TransferLog logs/?? (虛擬主機存取記載要存放的個(gè)目錄,可不設.)
</VirtualHost> (結束,要設第二組虛擬主機在從開(kāi)頭開(kāi)始設)
[b]在A(yíng)pache中的配置:[/b]
NameVirtualHost 166.166.166.166
<VirtualHost 166.166.166.166>
ServerAdmin [email]admin@test.com[/email]
DocumentRoot /your/web/file/dir
ServerName test.com
ServerAlias [url]www.test.com[/url]
ServerAlias pub.test.com
ErrorLog logs/test.com_error_log
TransferLog logs/test.com_transfer_log
</Virtualhost>
[b]如果沒(méi)有條件設置域名,在windows環(huán)境下可以做如下測試:[/b]
修改hosts主機文件,用記事本打開(kāi):
C:\WINNT\system32\drivers\etc\hosts
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
[b]加入:[/b]
166.166.166.166 test.com
166.166.166.166 [url]www.test.com[/url]
166.166.166.166 pub.test.com
在CMD下測試PING這三個(gè)域名,如果通,就可以測試apache了。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。