本文重點(diǎn)講解基于IP 和多端口的虛擬主機(jī)配置;單個(gè)IP地址的服務(wù)器上基于域名的虛擬主機(jī)配置;在多個(gè)IP 地址的服務(wù)器上配置基于域名的虛擬主機(jī);在不同的端口上運(yùn)行不同的站點(diǎn)(基于多端口的服務(wù)器上配置基于域名的虛擬主機(jī));基于域名和基于IP 的混合虛擬主機(jī)的配置;基于IP地址的虛擬主機(jī)配置方法
很多朋友在初次使用apache虛擬主機(jī)時(shí),都會(huì)覺(jué)得apache虛擬主機(jī)特別難配置,其實(shí)不然,只要掌握虛擬主機(jī)的配置原則,你就會(huì)發(fā)現(xiàn)要配置好一臺(tái)虛擬主機(jī)其實(shí)很簡(jiǎn)單,話(huà)不多說(shuō)直接看如何配置?
基于IP 和多端口的虛擬主機(jī)配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
單個(gè)IP地址的服務(wù)器上基于域名的虛擬主機(jī)配置
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>
在多個(gè)IP 地址的服務(wù)器上配置基于域名的虛擬主機(jī)
Listen 80
# This is the "main" server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver
# This is the other address
NameVirtualHost 172.20.30.50
<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here ...
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here ...
</VirtualHost>
在不同的端口上運(yùn)行不同的站點(diǎn)(基于多端口的服務(wù)器上配置基于域名的虛擬主機(jī))
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example1.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example1.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>
基于域名和基于IP 的混合虛擬主機(jī)的配置
Listen 80
NameVirtualHost 172.20.30.40
<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>
<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>
基于IP地址的虛擬主機(jī)
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /home/httpd/html1
ServerName www.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /home/httpd/html2
ServerName www.ok2.com
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
</VirtualHost>
通過(guò)閱讀這篇文章你是否掌握了apache虛擬主機(jī)配置方法?其實(shí)要配置好一臺(tái)虛擬主機(jī)沒(méi)有想象中那么難。
河南億恩科技股份有限公司(mszdt.com)始創(chuàng)于2000年,專(zhuān)注服務(wù)器托管租用,是國(guó)家工信部認(rèn)定的綜合電信服務(wù)運(yùn)營(yíng)商。億恩為近五十萬(wàn)的用戶(hù)提供服務(wù)器托管、服務(wù)器租用、機(jī)柜租用、云服務(wù)器、網(wǎng)站建設(shè)、網(wǎng)站托管等網(wǎng)絡(luò)基礎(chǔ)服務(wù),另有網(wǎng)總管、名片俠網(wǎng)絡(luò)推廣服務(wù),使得客戶(hù)不斷的獲得更大的收益。
服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話(huà):
0371-60135900
虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話(huà):
0371-55621053
網(wǎng)絡(luò)版權(quán)侵權(quán)舉報(bào)電話(huà):
0371-60135995
服務(wù)熱線(xiàn):
0371-60135900