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

admin3年前主机评测40

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

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

相关文章

传说中的反向代理,Nginx+Apache软件配置Web服务器

前言nginx和apache是互联网时代最为流行的两种Web服务器软件。nginx高并发性能出众,占用系统资源少,成为了很多企业web服务器的首选。但是由于nginx对于处理php等动态页面的处理十分...

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

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

Apache中利用mod_rewrite实现防盗链

 前提Apache中的mod_rewrite模块为激活状态,既然要消灭掉mp3文件的盗链就顺便也把图片盗链的设置给做了,下面是我在网站根目录的.htaccess文件中的配置,供同病相怜之人参...

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

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

一篇文章搞懂Nginx是什么,能干什么

Nginx的产生没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器。基于REST架构风格,以统一资源描述符(Uniform...

Apache下怎么提高服务器的安全性

Apache下提高服务器安全性的方法:1、建立一个.htaccess文件,输入相关代码提高服务器的安全性,这种方法主要适用于没有服务器管理权限;2、修改apache配置文件,在配置中增加相关代码,这种...