apache 設(shè)置主機(jī)頭,同一端口綁定多個域名和網(wǎng)站
一臺服務(wù)器安裝了APACHE,如何綁定多個域名和網(wǎng)站內(nèi)容呢?最簡單的方法當(dāng)然就是不同的站用不同的端口。但這樣就需在域名后加入端口號才能訪問,不能直接以域名訪問。另一個方法就是使用主機(jī)頭名虛所主機(jī)了。打
一臺服務(wù)器安裝了APACHE,如何綁定多個域名和網(wǎng)站內(nèi)容呢?最簡單的方法當(dāng)然就是不同的站用不同的端口。但這樣就需在域名后加入端口號才能訪問,不能直接以域名訪問。另一個方法就是使用主機(jī)頭名虛所主機(jī)了。打開APACHE配置文件httpd.conf 在最后一行輸入以下代碼
NameVirtualHost *:80 #使用虛擬主機(jī),80端口
DocumentRoot “D:/root/abc” #指向本地位置
ServerName www.abc.com #主機(jī)名稱(注意這個很重要,就是你的域名,準(zhǔn)確輸入才能成功)
DocumentRoot “D:/root/def” #指向本地位置
ServerName www.def.com #主機(jī)名稱
DocumentRoot “D:/root/ghi” #指向本地位置
ServerName www.ghi.com #主機(jī)名稱
如此類推,只要你的機(jī)性能好,帶寬夠,多掛幾個都可以
Aapche 如果需要綁定多個域名到一個IP上,是支持的。需要注意以下2點(diǎn):
1 必須要開啟 NameVirtualHost開關(guān)選項,
如:NameVirtualHost 220.231.220.231:80
2 NameVirtualHost 需要指定具體的端口
例如":80",跟
mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results。
翻譯過來就是: NameVirtualHost 地址,指定端口和不指定端口混合使用是不支持的,將會產(chǎn)生未逾期的后果。
未逾期的后果就是: 第2個不起作用,僅當(dāng)一個站點(diǎn)設(shè)置起作用。
完整的例子:
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
NameVirtualHost 219.133.61.226:80
ServerAdmin hot@vip.qq.com
DocumentRoot /usr/local/apache2/htdocs1
ServerName www.linux51.com
ErrorLog logs/linux51.com-error_log
CustomLog logs/linux51.com-access_log common
ServerAdmin hot@vip.qq.com
DocumentRoot /usr/local/apache2/htdocs2
ServerName www.linux52.com
ErrorLog logs/linux52.com-error_log
CustomLog logs/linux52.com-access_log common