在网上查了很多资料配置Apache的虚拟主机,但都是讲得一知半解,没有系统、完整的配置过程。
经自己研究后,得到了完整版的配置方法。
以下设置方法是基于WindowsXP的设置方法
调试:在本机进行调试
1、安装Apache
省略
2、配置Apache
打开Apache的配置文件httpd.conf,位置:在Apache安装路径下的conf下
找到以下内容,指定Apache的端口号,这里设置为:80
继续:
设置Web站点的路径,这里指定为以下:
<Directory "D:/WorkSpace/ApacheWebs">
以上的设置只是Apache的常规设置,如果不设置虚拟主机的话,使用以上设置就可以完成Web服务的配置了。
3、配置Apache虚拟主机
继续以上步骤:
将Include前的#去掉
# Virtual hostsInclude conf/extra/httpd-vhosts.conf
保存修改后的httpd.conf
4、配置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>
ServerAdmin [email protected]
DocumentRoot "D:/WorkSpace/ApacheWebs2"
ServerName www.test1.com
ServerAlias www.dummy-host.test
ErrorLog "logs/dummy-host.test-error.log"
CustomLog "logs/dummy-host.test-access.log" common
</VirtualHost>
<Directory "D:/WorkSpace/ApacheWebs2">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:/WorkSpace/ApacheWebs3"
ServerName www.test2.com
ErrorLog "logs/dummy-host2.test-error.log"
CustomLog "logs/dummy-host2.test-access.log" common
</VirtualHost>
<Directory "D:/WorkSpace/ApacheWebs3">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
上面的配置文件中设置了两个虚拟主机,对应的服务器名及Web站点目录名分别为:
ServerName:www.test1.com -> D:/WorkSpace/ApacheWebs2
ServerName:www.test2.com -> D:/WorkSpace/ApacheWebs3
[Directory]的标签使用来设置目录的访问权限的,如果不设置的话,会出现403的错误。如果不希望站点显示目录的话,可以将[Directory]中Options的Indexes前加上[-],即:
<Directory "D:/WorkSpace/ApacheWebs3">Options -Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory> 以上配置结束后,保存文件.
并重新启动Apache服务即可.
如果是本地调试的话,还需要修改一下Hosts文件,否则的话。。。,你自己试试就知道了
打开c:windowssystem2driversetcHosts文件
加入以下代码:
127.0.0.1 www.test1.com127.0.0.1 www.test2.com 打开IE,分别输入:
http://www.test1.com
http://www.test2.com
就可以看到效果了。
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。