apache下多站点的架设

in Develop

这里是指同一IP绑定N个域名,有二种方式实现
方法1、仅修改httpd.conf
假设二个域名bbs.xxx.com与blog.xxx.com
打开httpd.conf
将文件拖到最下面,加上

<VirtualHost *:80>
ServerName bbs.xxx.com #域名
DocumentRoot “F:/website/bbs” #该域名对应的目录地址
<Directory “F:/website/bbs”> #该节点是配置权限、默认首页啊等等东东。
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.php
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName blog.xxx.com
DocumentRoot “D:/PHPSite/wordpress”
<Directory “D:/PHPSite/wordpress”>
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.php
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>

重启apache,就OK啦。当然你要修改你的hosts文件。

方法2、修改PhpServerApache2.2confextrahttpd-vhosts.conf
直接将上面一段copy到httpd-vhosts.conf的最后即可。
实际上看名字就知道httpd-vhosts.conf是一个虚拟站点配置集中地,方便管理。
也就是如下:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost *:80>
ServerName bbs.xxx.com #域名
DocumentRoot “F:/website/bbs” #该域名对应的目录地址
<Directory “F:/website/bbs”> #该节点是配置权限、默认首页啊等等东东。
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.php
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName blog.xxx.com
DocumentRoot “D:/PHPSite/wordpress”
<Directory “D:/PHPSite/wordpress”>
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.php
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>

重启apache。
如果不行的话,看你的httpd.conf是否启用了vhost
打开httpd.conf,找到
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
看是否启用,即去掉Include conf/extra/httpd-vhosts.conf前的#
重启apache,爽去吧。

6 Comments

6 Comments

  1. 哈,照你的方法搞定了:up:

  2. 其实叫虚拟主机更确切点.
    另外 VirtualHost 段中可以只需要一个 DocumentRoot 和 ServerName 就够了
    后面的 Directory 可以从默认配置中继承

  3. 我就是想不通了,我写了个邮件系统,但老是无法用相对目录,明明在webapps/isite是个网站,但常常会到webapps里面去找东西,我真快疯了。

  4. @邮件系统:
    看看我写的是否对你有帮助。

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>