Apache虛擬主機(jī)的配置和泛域名解析實(shí)現(xiàn)代碼
2024-08-27 18:27:58
供稿:網(wǎng)友
虛擬主機(jī)的配置
基于IP地址的虛擬主機(jī)配置
Listen 80
DocumentRoot /www/jb51
ServerName www.companysz.com
DocumentRoot /www/jb512
ServerName www.jb512.org
基于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
DocumentRoot /www/jb51-80
ServerName www.companysz.com
DocumentRoot /www/jb51-8080
ServerName www.companysz.com
DocumentRoot /www/example2-80
ServerName www.jb51.org
DocumentRoot /www/example2-8080
ServerName www.example2.org
單個IP地址的服務(wù)器上基于域名的虛擬主機(jī)配置:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
DocumentRoot /www/jb51
ServerName www.companysz.com
ServerAlias Vevb.com. *.Vevb.com
# Other directives here
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
在多個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
DocumentRoot /www/jb51
ServerName www.companysz.com
# Other directives here …
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …
在不同的端口上運(yùn)行不同的站點(diǎn):
基于多端口的服務(wù)器上配置基于域名的虛擬主機(jī)。
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
ServerName www.companysz.com
DocumentRoot /www/domain-80
ServerName www.companysz.com
DocumentRoot /www/domain-8080
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
基于域名和基于IP的混合虛擬主機(jī)的配置:
Listen 80
NameVirtualHost 172.20.30.40
DocumentRoot /www/jb51
ServerName www.companysz.com
DocumentRoot /www/example2
ServerName www.example2.org
DocumentRoot /www/example3
ServerName www.example3.net
網(wǎng)站泛域名解析
添加一個虛擬主機(jī)配置(如下):
DocumentRoot d:/web/jb51 # 網(wǎng)站根目錄的絕對路徑
ServerName www.companysz.com # 網(wǎng)站域名
ServerAlias *.Vevb.com # 網(wǎng)站泛域名
APACHE泛域名配置參考
NameVirtualHost 192.168.0.110
<VirtualHost 192.168.0.110:80>
DocumentRoot "E:/InterRoot/workplace/"