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

admin3年前主机评测45

虚拟主机的配置
  基于IP地址的虚拟主机配置
  Listen 80
  DocumentRoot /www/zz
  ServerName zz
  DocumentRoot /www/zz2
  ServerName 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 zz
  DocumentRoot /www/zz-8080
  ServerName zz
  DocumentRoot /www/example2-80
  ServerName zz.org
  DocumentRoot /www/example2-8080
  ServerName 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 zz
  ServerAlias zz. *.zz
  # Other directives here
  DocumentRoot /www/example2
  ServerName example2.org
  # Other directives here
  在多个IP地址的服务器上配置基于域名的虚拟主机:
  Listen 80
  # This is the “main” server running on 172.20.30.40
  ServerName server.domain
  DocumentRoot /www/mainserver
  # This is the other address
  NameVirtualHost 172.20.30.50
  DocumentRoot /www/zz
  ServerName zz
  # Other directives here …
  DocumentRoot /www/example2
  ServerName example2.org
  # Other directives here …
  在不同的端口上运行不同的站点:
  基于多端口的服务器上配置基于域名的虚拟主机。
  Listen 80
  Listen 8080
  NameVirtualHost 172.20.30.40:80
  NameVirtualHost 172.20.30.40:8080
  ServerName zz
  DocumentRoot /www/domain-80
  ServerName zz
  DocumentRoot /www/domain-8080
  ServerName example2.org
  DocumentRoot /www/otherdomain-80
  ServerName example2.org
  DocumentRoot /www/otherdomain-8080
  基于域名和基于IP的混合虚拟主机的配置:
  Listen 80
  NameVirtualHost 172.20.30.40
  DocumentRoot /www/zz
  ServerName zz
  DocumentRoot /www/example2
  ServerName example2.org
  DocumentRoot /www/example3
  ServerName example3
  网站泛域名解析
  添加一个虚拟主机配置(如下):
  
  DocumentRoot d:/web/zz # 网站根目录的绝对路径
  ServerName zz # 网站域名
  ServerAlias *.zz # 网站泛域名

APACHE泛域名配置参考

NameVirtualHost 192.168.0.110

<VirtualHost 192.168.0.110:80>
DocumentRoot "E:/InterRoot/workplace/"
ServerName workplace
<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 test
<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
ServerAlias auth.billing *.auth.billing
#泛域名解析
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
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
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
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
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
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
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>

免责声明:本文内容来自用户上传并发布,站点仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请核实广告和内容真实性,谨慎使用。

相关文章

建站选虚拟主机还是云主机

建站选择虚拟主机和云主机的方法:1、如果资金预算有限且网站暂时不能带来更多利益,哪就选择虚拟主机,虚拟主机适合新手建站、小型网站、流量少的站点使用;2、如果网站有更高的安全需求,更大的计算性能需求,或...

北京虚拟主机租用价格是多少

北京虚拟主机的租用价格会因为不同的服务器配置、使用时长等因素而有所不同,一般来说,北京的虚拟主机租用价格在几十元到几百元之间,也有提供年付优惠的。1、核心数量控制服务器的处理速度,一般来说,越多的核心...

租赁虚拟主机有什么坏处

租赁虚拟主机的坏处有:1.环境无法订制,只能用服务商提供的环境;2.无法拓展,配置无法升级;3.容易受牵连,受其他虚拟主机牵连;具体分析如下:1.环境无法订制租赁虚拟主机只能是虚拟主机服务商提供什么环...

租用虚拟主机提高网站安全的三个技巧

现在网络攻击越来越多,而且攻击方式也非常多样,因此为了确保网站用户和数据的安全,提高网站的安全性和做好相关的安全防御措施很重要的。那么租用虚拟主机提高网站安全怎样做呢?下面小编就给大家分享几个技巧。使...

对虚拟主机商而言VPS主机有哪些缺点

对虚拟主机商而言VPS主机的缺点有:1、IP地址需求紧张,容易出现机柜和机位还空着没有租出去的情况;2、技术成本更高,需要花费大量时间做测试和内部培训;3、软件成本更高,VPS主机需要使用一个VPS软...

物理云服务器和虚拟主机有哪些区别

物理云服务器和虚拟主机的区别有:1、使用不同,物理云服务器使用前,要先进行操作系统安装,且后期要时刻关注服务器的各种指标和运行情况,虚拟主机由技术人员设置好一切,用户把网站数据上传到网站空间就能马上使...