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

admin3年前主机评测65

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

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

相关文章

Ubuntu16.04搭建WordPress的方法(ubuntu部署wordpress)

Ubuntu16.04搭建WordPress的方法及ubuntu部署wordpressWordPress是一款非常流行的开源博客系统,它拥有丰富的插件和主题资源,可以满足不同用户的需求。而Ubuntu...

Apache怎么在本地建立泛域名虚拟主机

Apache在本地建立泛域名虚拟主机的方法:1、修改apache安装目录下的conf/httpd.conf文件;2、修改完成后保存,然后重启apache;3、打开c:\windows\system32...

WEB服务器该选择 Apache 还是 Nginx?

Web服务器一般指网站服务器,是指驻留于因特网上某种类型计算机的程序,可以向浏览器等Web客户端提供文档。你可以放置网站文件,让全世界浏览;可以放置数据文件,让全世界下载。目前最主流的三个Web服务器...

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

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

Apache源码安装和虚拟主机配置的教程详解

源码安装Apache 1.上传Apache源码安装所需软件包2.安装:安装顺序apr—>apr-util—>pcre—>httpd安装编...

phpStudy找不到Apache“服务名” 解决方法

这篇文章主要为大家详细介绍了phpStudy找不到Apache“服务名” 解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。今天一用...