虚拟主机的配置
基于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>
Apache虚拟主机的配置和泛域名解析实现代码
2021-04-12 01:40主机之家 虚拟主机
Apache虚拟主机的配置和泛域名解析实现代码,需要的朋友可以参考下
延伸 · 阅读
- 2022-03-10Apache访问日志的配置与使用
- 2022-03-10使用Apache commons-cli包进行命令行参数解析的示例
- 2022-03-09Ubuntu 16.04与Apache虚拟主机配置的步骤详解
- 2022-03-06Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方
- 2022-03-06CentOS 7中 Apache Web 服务器安装配置教程
- 2022-03-03APACHE服务器出现No input file specified.的完美解决方
- 虚拟主机
星外系统IIS日志分析常用的几个命令小结
星外系统IIS日志分析常用的几个命令小结,使用星外系统IIS日志分析工具的朋友可以参考下...
- 虚拟主机
美国虚拟主机访问不稳定是为什么?
看到网上有用户反映自己购买了美国的虚拟主机,使用了一段时间,突然发现网站访问变得不稳定了,这是什么原因呢?我们来跟着VPS主机之家一同看看。...
- 虚拟主机
ASP空间和PHP空间哪个好
经常有客户问我,ASP空间好,还是PHP空间好,今天服务器之家小编从SEO的角度给大家分析一下这个问题。...
- 虚拟主机
阿里云虚机主机支持301重定向吗?怎么设置?
阿里云虚机主机支持301重定向吗?怎么设置? 答:虚拟主机 除M2型和共享虚拟主机普惠版外以外都支持301重定向。 登陆主机管理控制台-基础环境设置-30...
- 虚拟主机
虚拟主机下实现多域名绑定不同的子目录的方法
虚拟主机下实现多域名绑定不同的子目录的方法,支持asp、php、html,有需要的朋友可以参考下...
- 虚拟主机
外贸建站选美国空间还是香港空间好?
由于外贸站的用户都是海外的,选择国内的主机已经无法让网站正常访问,所以选择美国、香港等主机就很有必要。那么,外贸建站选美国空间还是香港空...
- 虚拟主机
虚拟主机买哪种的好?
虚拟主机买哪种的好?虚拟主机根据实际应用需求来买就是比较好的。比如搭建网站,根据网站数据情况选择空间大小,根据网站访问量选择月流量多少。还...
- 虚拟主机
从价格角度看虚拟主机空间性价比
诚然,挑选虚拟主机空间必须清楚自身的需求,以需求情况来设定一个合理的预算,这样才可以是主机空间的性价比达到最高,这里就以空间价格为前提来...