Apache配置虚拟主机
1.方式一:使用不同的服务端口,启动多个apache服务实例,使用各自的配置文件
1)配置文件中添加监听的端口
Listen801
Listen802
2)
<VirtualHost*:801>
ServerAdminwww@13.com
DocumentRoot"E:/webserver/www/thinkphp"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/thinkphp">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
<VirtualHost*:802>ServerAdminwww@13.com
DocumentRoot"E:/webserver/www/learnlaravel5"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/learnlaravel5">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
3)重启服务器
2.方式二:同一个端口,配置多个虚拟主机
一、配置HOST文件
首先在你的系统盘下windows/system32/drivers/etc/host
二、修改httpd.conf
需要开启httpd.conf的LoadModulerewrite_modulemodules/mod_rewrite.so
去掉Includeconf/extra/httpd-vhosts.conf前的#注释
三、配置httpd-vhosts.conf
NameVirtualHost127.0.0.1:80
<VirtualHostweb.shops.com:80>
DocumentRoot"D:\AppServ\www\shops"
ServerNameweb.shops.com
<Directory"D:\AppServ\www\shops">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
*访问虚拟主机如果出现Forbidden You don't have permission to access/onthisserver错误
这是因为新建的虚拟主机的目录没有读权限。做如下操作:
1.把相应目录的权限改为可读。
2.在虚拟主机配置后面添加如下代码
<Directory"D:/Web">
OptionsFollowSymLinks
AllowOverrideNone
Orderdeny,allow
Allowfromall
</Directory>
Apache配置虚拟目录
编辑httpd.conf文件,增加
Alias/xx“实际目录路径”
和上面虚拟主机的配置一样,下面也需要加目录权限配置<Directory>,否则也不能访问。