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

admin3年前主机评测64

虚拟主机的配置
  基于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>

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

相关文章

Apache 配置详解(最好的APACHE配置教程)

Apache的配置Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改。 主站点的配置(基本配置)(1) 基本配置:ServerRoot...

Apache为mysql以及自己的项目设置虚拟路径

1.Apache2.2\conf\httpd.conf中释放:Include conf/extra/httpd-vhosts.conf(去掉前面的#)2.httpd.conf中增加<Direct...

Windows环境开发PHP完整配置教程Apache+Mysql+PHP

软件准备:主要讲解Apache,Mysql,PHP,以及PhpMyAdmin的安装配置。开发工具自备。Apache的安装:注:本例只截取需要注意的截图,其它默认则不显示。1.服务器信息可以按照默认配置...

有哪个好用的香港云服务器?(有哪个好用的香港云服务器软件)

及有哪个好用的香港云服务器软件随着互联网的快速发展,越来越多的企业和个人开始将自己的业务迁移到云端。而在云计算领域中,云服务器是最为常见和重要的一种云计算服务。对于需要面向中国大陆用户的企业或个人,选...

Apache,IIS下Discuz x1.5伪静态设置方法

1.如是Apache服务器,操作如下:建立.htaccess文件,在该文件里面写入如下伪静态规则:复制代码 代码如下:# 将 RewriteEngine 模式打开RewriteEngine On# 修...

linux下要怎样安装php环境(linux怎么安装php环境)

本文将介绍如何在Linux系统中安装PHP环境。在Ubuntu系统中,使用以下命令安装Apache:```sudo apt-get updatesudo apt-get install apache2...