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

虚拟主机的配置
  基于IP地址的虚拟主机配置
  Listen 80
  DocumentRoot /www/jb51
  ServerName www.jb51.net
  DocumentRoot /www/jb512
  ServerName www.jb512.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/jb51-80
  ServerName www.jb51.net
  DocumentRoot /www/jb51-8080
  ServerName www.jb51.net
  DocumentRoot /www/example2-80
  ServerName www.jb51.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/jb51
  ServerName www.jb51.net
  ServerAlias jb51.net. *.jb51.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/jb51
  ServerName www.jb51.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.jb51.net
  DocumentRoot /www/domain-80
  ServerName www.jb51.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/jb51
  ServerName www.jb51.net
  DocumentRoot /www/example2
  ServerName www.example2.org
  DocumentRoot /www/example3
  ServerName www.example3.net
  网站泛域名解析
  添加一个虚拟主机配置(如下):
  
  DocumentRoot d:/web/jb51 # 网站根目录的绝对路径
  ServerName www.jb51.net # 网站域名
  ServerAlias *.jb51.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>

(0)

相关推荐

  • apache虚拟主机中设置泛域名解析的方法

    1.支持多域名 例如,让mail.jbxue.org.smtp.jbxue.org.pop3.jbxue.org 都指向同一个虚拟主机,可以写成: 复制代码 代码如下: ServerName mail.jbxue.orgServerAlias smtp.jbxue.org pop3.jbxue.org ServerName 用于指定首选域名,其他的域名用ServerAlias指定,并用空格区分即可. 2.支持泛域名解析ServerAlias 可支持扩展符,例如,我们希望 xx.a.com 下的所

  • 分享三种Apache配置虚拟主机的方式

    一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [root@localhost root]# ifconfig eth0:1 192.168.1.11 [root@localhost root]# ifconfig eth0:2 192.168.1.12 [root@localhost root]# ifconfig eth0:3 192.168.1.13 2. 修改hosts文件,添加三个域名与之一一对应: 1

  • 本地机apache配置基于域名的虚拟主机详解

    1.打开apache的httpd.conf文件,找到# Virtual hosts#Include conf/extra/httpd-vhosts.conf这一段把Include conf/extra/httpd-vhosts.conf前面的"#"去掉. 2.修改位于(win7)c:/windows/system32/drivers/etc/目录下的hosts文件增加一段:127.0.0.1    x.acme.com(你用来访问的域名) 3.我用的是wamp包,所以到c:/wamp/

  • Apache 配置多端口 多虚拟主机 局域网访问示例

    一.在\wamp\bin\apache\Apache2.4.4\conf\extra\httpd-vhosts.conf 修改如下 复制代码 代码如下: NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "E:/website/pxsj" ServerName host7.com ServerAlias 192.168.1.116 <Directory "E:/website/pxsj">

  • apache中伪静态配置和使用(Apache虚拟主机下Discuz伪静态)

    一 打开 Apache 的配置文件 httpd.conf . 二 将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉 三 在 httpd.conf中添加: <IfModule mod_rewrite.c> RewriteEngine On #RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+\.html RewriteRule ^(.*?(?:index|dispbbs))-([-

  • apache服务器一个ip(如:127.0.0.1)和多个域名(虚拟主机)的绑定

    今天在学习PHP时,有这样的一个需求:一个ip(如:127.0.0.1)和多个域名(虚拟主机)绑定,以下是我的解决方案: 解决方案一:通过端口来区分不同的虚拟主机 ①按照绑定一个站点的方法做好准备 1. 先开发好自己的网站(d:/myblog(存放在D盘的myblog目录下)) 2. 配置httpd.conf文件(存放在apache安装目录的conf文件夹中),启用httpd-vhosts.conf(把第二行前面的#号去掉即可). 3. 配置httpd-vhosts.conf文件(存放在apac

  • Apache实现本地建立泛域名虚拟主机的方法

    本文讲述了Apache实现本地建立泛域名虚拟主机的方法.分享给大家供大家参考,具体如下: 在本地建立泛域名虚拟主机,可以修改Apache的安装目录下的conf/httpd.conf,如下: <VirtualHost *:80> ServerName auciou.com ServerAlias *.auciou.com DocumentRoot F:/site/auciou </VirtualHost> 重启Apache,就可以在本地同时使用auciou.com和xxx.aucio

  • apache虚拟主机三种配置方式小结

    使用虚拟主机必须要注释掉httpd的主机模块,即修改httd.conf的主配置文件,找到,将这段内容注释掉就可以了. apche的虚拟主机配置一共有三种,即基于IP.基于port.以及基于域名的.为了后面试验,需要配置两个IP地址(我主机现在的IP地址是10.10.50.100),命令如下: #ip addr add 10.10.50.101/16 dev eth0 #ip addr add 10.10.50.102/16 dev eth0 关于如何配置IP地址,此处不再赘述,后面我会专门写篇关

  • 如何配置apache虚拟主机的实例小结

    1.基于ip地址的虚拟主机 复制代码 代码如下: Listen 80<VirtualHost 172.20.30.40>    DocumentRoot /home/httpd/html1    ServerName www.ok1.com    ErrorLog /usr/local/apache/logs/error1_log    CustomLog /usr/local/apache/logs/access1_log combined</VirtualHost><Vi

  • windows apache多端口虚拟主机配置方法

    1.打开httpd.conf,查找Listen:80,在下面一行加入Listen:8080:2.查找#Include conf/extra/httpd-vhosts.conf,将此行前面的#去掉:3.打开httpd.conf文件目录下面的extra文件夹下面的httpd-vhosts.conf文件:4.查找NameVirtualHost *:80,在下面一行增加NameVirtualHost *:8080:5.复制httpd-vhosts.conf文件最下面的如下代码,并且在下面粘贴一份: 复制

随机推荐