APACHE 配置虚拟主机和虚拟目录

Apache 配置虚拟主机

  1. 方式一:使用不同的服务端口,启动多个apache服务实例,使用各自的配置文件

1)  创建配置文件:复制httpd.conf 另存为mysite.conf(名字自定)

2)  修改新配置文件里的监听端口:找到“Listen:80” 改为“Listen:8080”(80以外的端口)

3)  设置站点目录:指定 DocumentRoot “×××××” 和<Directory “××××”>的目录名

4)  新建一个服务:httpd -k install -n “服务名” -f “配置文件路径”

  1. 方式二:同一个端口,配置多个虚拟主机

1)  修改配置httpd.conf

  1. 注释掉DocumentRoot
  2. 找到Include conf/extra/httpd-vhosts.conf,如果有注释则打开

2)  修改配置文件/conf/extra/httpd-vhosts.conf

  1. 去掉NameVirtualHost的注释,NameVirtualHost  ip:80 (本机ip或*:80 表示所有ip)
  2. 增加虚拟主机的配置。Httpd-vhosts.conf里有例子

<VirtualHost *:80>

ServerName “localhost”

DocumentRoot “/www/root”

</VirtualHost>

<VirtualHost *:80>

ServerName “localhost2″

DocumentRoot “/www/root2″

</VirtualHost>

* 访问虚拟主机如果出现

Forbidden
You don’t have permission to access / on this server 错误

这是因为新建的虚拟主机的目录没有读权限。做如下操作:

1. 把相应目录的权限改为可读。

2. 在虚拟主机配置后面添加如下代码

<Directory “D:/Web”>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>

 

Apache 配置虚拟目录

1、配置虚拟目录就是增加一个节点,找到<IfModule>这块,加入下面的代码;
view plaincopy
# 虚拟目录,访问D盘下面的web目录
<IfModule dir_module>
# 设置缺省载入页面
DirectoryIndex index.html index.htm index.php
# 设置站点别名,别名与访问路径是相关的,取任何名称都可以(除特殊)
Alias /myweb “D:/web”
<Directory D:/web>
# 设置访问权限
Order allow,deny
Allow from all
</Directory>
</IfModule>

posted @ 2014-09-24 01:13  泪痕湮灭  Views(230)  Comments(0)    收藏  举报