通过不同的域名来访问根目录和根目录下的子目录

来源:互联网 发布:女装淘宝首页 编辑:程序博客网 时间:2024/05/19 03:18

wampserver的根目录为www目录,子目录为www\aaa,通过域名www.111.com访问www目录,通过域名www.222.com访问www\aaa目录,操作步骤如下

1)左键右下角的wampserver图标,打开apache->httpd.cof,找到

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

改为

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

保存退出。

2)配置vhost文件,打开wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf

在最后加上

<VirtualHost *:80>
    ServerAdmin xxx@qq.com
    DocumentRoot "F:/wt/wampServer/setUpDir/wamp/www"
    ServerName www.111.com
    ServerAlias www.111.example.com
    ErrorLog "logs/111.example.com-error.log"
    CustomLog "logs/111.example.com-access.log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin xxx@qq.com
    DocumentRoot "F:/wt/wampServer/setUpDir/wamp/www/aaa"
    ServerName www.222.com
    ServerAlias www.222.example.com
    ErrorLog "logs/222.example.com-error.log"
    CustomLog "logs/222.example.com-access.log" common
</VirtualHost>

保存退出


3)重启wampserver

4)修改hosts文件,做好域名映射

打开C:\Windows\System32\drivers\etc\hosts

在最后加上

192.168.1.16       www.111.com
192.168.1.16       www.222.com

保存退出

说明:上面192.168.1.16 是本机的ip,因为两个域名是没有在域名服务器上注册的,所以,只能在本机通过域名访问

0 0