关于如何配置虚拟主机,下面有两个实例,我们可以跟据这两个实例来配置我们的虚拟主机:
实例一,Apaceh配置localhost虚拟主机步骤
1,用记事本打开apache目录下httpd文件(如:D:\wamp\bin\apache\apache2.2.8\conf),找到如下模块
# Virtual hosts#Include conf/extra/httpd-vhosts.conf往掉#Include conf/extra/httpd-vhosts.conf前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd-vhosts.conf配置一下。我的wamp安装在D盘
2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd-vhosts文件中实例,修改成如下:
<VirtualHost *:80>ServerAdmin DocumentRoot "D:\wamp\www"ServerName localhostServerAlias localhostErrorLog "logs/dummy-host.localhost-error.log"CustomLog "logs/dummy-host.localhost-access.log" common</VirtualHost>修改配置如下:
DocumentRoot 修改为本地wamp环境下的www目录(如:D:\wamp\www)
ServerName改为localhost
3,重启Apache,发现localhost可以正常打开,配置localhost比较简单。
实例二,Apaceh配置test.biuuu.com虚拟主机步骤
1,方法同上,复制配置代码修改如下:
<VirtualHost *:80>
ServerAdmin
DocumentRoot "d:/wamp/www/magento"
ServerName www.jiangpeng.com
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>2,打开host文件(C:\WINDOWS\system32\drivers\etc\hosts),增加一行代码
127.0.0.1 www.jiangpeng.com3,在浏览器中打开www.jiangpeng.com,发现如下错误403 Forbidden错误
Forbidden
You don't have permission to access / on this server.
分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!
4,打开httpd文件,找到如下语句
<Directory />Options FollowSymLinksAllowOverride NoneOrder deny,allowDeny from all</Directory>复制以上代码,并进行目录修改,把/替换为d:/wamp/www/magento,修改virtualHost代码如下
<VirtualHost *:80>ServerAdmin "d:/wamp/www/magento"ServerName www.jiangpeng.comErrorLog "logs/dummy-host2.localhost-error.log"CustomLog "logs/dummy-host2.localhost-access.log" common</VirtualHost><Directory "d:/wamp/www/magento">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
在浏览器中测试发现还是打不开,提示如上403 Forbidden错误,修改其中的Deny from all为allow from all
5,重启Apache,虚拟主机配置成功!
留意事项
1,目录路径,如d:/wamp/www/magento
2,访问权限,如上Deny from all修改为allow from all
3,host文件,配置虚拟域名host指向
4,httpd文件,打开Include conf/extra/httpd-vhosts.conf模块
5,httpd-vhosts文件,配置虚拟主机