Apache虚拟主机的配置和泛域名解析实现代码
程序员文章站
2022-06-14 14:41:02
虚拟主机的配置 基于ip地址的虚拟主机配置 listen 80 documentroot /www/jb51 servername www.jb51.net...
虚拟主机的配置
基于ip地址的虚拟主机配置
listen 80
documentroot /www/jb51
servername www.jb51.net
documentroot /www/jb512
servername www.jb512.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/jb51-80
servername www.jb51.net
documentroot /www/jb51-8080
servername www.jb51.net
documentroot /www/example2-80
servername www.jb51.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/jb51
servername www.jb51.net
serveralias jb51.net. *.jb51.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/jb51
servername www.jb51.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.jb51.net
documentroot /www/domain-80
servername www.jb51.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/jb51
servername www.jb51.net
documentroot /www/example2
servername www.example2.org
documentroot /www/example3
servername www.example3.net
网站泛域名解析
添加一个虚拟主机配置(如下):
documentroot d:/web/jb51 # 网站根目录的绝对路径
servername www.jb51.net # 网站域名
serveralias *.jb51.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>
基于ip地址的虚拟主机配置
listen 80
documentroot /www/jb51
servername www.jb51.net
documentroot /www/jb512
servername www.jb512.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/jb51-80
servername www.jb51.net
documentroot /www/jb51-8080
servername www.jb51.net
documentroot /www/example2-80
servername www.jb51.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/jb51
servername www.jb51.net
serveralias jb51.net. *.jb51.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/jb51
servername www.jb51.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.jb51.net
documentroot /www/domain-80
servername www.jb51.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/jb51
servername www.jb51.net
documentroot /www/example2
servername www.example2.org
documentroot /www/example3
servername www.example3.net
网站泛域名解析
添加一个虚拟主机配置(如下):
documentroot d:/web/jb51 # 网站根目录的绝对路径
servername www.jb51.net # 网站域名
serveralias *.jb51.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>