apache下多站点的架设

本文介绍在同一IP下绑定多个域名的两种方法。方法一通过直接修改httpd.conf文件实现;方法二则是更改httpd-vhosts.conf文件来设置虚拟主机。文章详细展示了如何配置Apache以支持两个不同的域名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里是指同一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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值