Apache虚拟主机的配置和泛域名解析实现代码

发布时间:2025-03-13 点击:16
虚拟主机的配置
基于ip地址的虚拟主机配置
listen 80
documentroot /www/zz
servername www.zz.net
documentroot /www/zz2
servername www.zz2.org
基于ip和多端口的虚拟主机配置
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/zz-80
servername www.zz.net
documentroot /www/zz-8080
servername www.zz.net
documentroot /www/example2-80
servername www.zz.org
documentroot /www/example2-8080
servername www.example2.org
单个ip地址的服务器上基于域名的虚拟主机配置:
# ensure that apache listens on port 80
listen 80
# listen for virtual host requests on all ip addresses
namevirtualhost *:80
documentroot /www/zz
servername www.zz.net
serveralias zz.net. *.zz.net
# other directives here
documentroot /www/example2
servername www.example2.org
# other directives here
在多个ip地址的服务器上配置基于域名的虚拟主机:
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/zz
servername www.zz.net
# other directives here …
documentroot /www/example2
servername www.example2.org
# other directives here …
在不同的端口上运行不同的站点:
基于多端口的服务器上配置基于域名的虚拟主机。
listen 80
listen 8080
namevirtualhost 172.20.30.40:80
namevirtualhost 172.20.30.40:8080
servername www.zz.net
documentroot /www/domain-80
servername www.zz.net
documentroot /www/domain-8080
servername www.example2.org
documentroot /www/otherdomain-80
servername www.example2.org
documentroot /www/otherdomain-8080
基于域名和基于ip的混合虚拟主机的配置:
listen 80
namevirtualhost 172.20.30.40
documentroot /www/zz
servername www.zz.net
documentroot /www/example2
servername www.example2.org
documentroot /www/example3
servername www.example3.net
网站泛域名解析
添加一个虚拟主机配置(如下):
documentroot d:/web/zz # 网站根目录的绝对路径
servername www.zz.net # 网站域名
serveralias *.zz.net # 网站泛域名
apache泛域名配置参考
namevirtualhost 192.168.0.110
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/workplace/"
servername www.workplace.com
<directory "e:/interroot/workplace/">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/busymouse_test/"
servername www.test.com
<directory "e:/interroot/busymouse_test/">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/auth"
servername auth.billing.com
serveralias auth.billing.com *.auth.billing.com
#泛域名解析
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/auth">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/api"
servername voiz.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/api">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/user"
servername user.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/user">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/center"
servername center.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/center">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/img"
servername img.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/img">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:/interroot/iptv_for_browser/log"
servername log.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:/interroot/iptv_for_browser/log">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 192.168.0.110:80>
documentroot "e:\interroot\billing_new\front"
servername admin.billing.com
errorlog "e:/interroot/iptv_for_browser/serverlog/apache.log"
<directory "e:\interroot\billing_new\front">
allowoverride fileinfo
options indexes followsymlinks includes
order allow,deny
allow from all
</directory>
</virtualhost>


快速打造高质量企业站的网站设计3个小技巧?
定制型网站建设优势明显,成为企业网站建设主流趋势!
如何降低企业网站的跳出率方法介绍
浅谈企业网站的策划
微商究竟在卖什么
图片库管理系统
企业网站建设必须关注的常识及应该确定的目标
网站收录多少对营销型网站优化排名的影响