1.事先建立兩個域名站點
分別建立web1和web2站點,分別建立主頁面web1.html和web2.html;
2.在httpd.conf文件中啟用httpd-vhosts.conf
去掉#,即
#Virtual hosts (虛擬主機)
Include conf/extra/httpd-vhosts.conf
3.設置http-vhosts.conf文件(路徑:X:/ApacheX.X/conf/extra/http-vhosts.conf)
添加以下內容:
#配置虛擬主機 <VirtualHost *:80> DocumentRoot "d:/web1" ServerName www.ayee1.com #配置歡迎首頁面 DirectoryIndex web1.html index.html index.htm index.php <Directory /> Options FollowSymLinks #不許別人修改網站頁面 AllowOverride None #設置訪問權限 Order allow,deny Allow from all </Directory> </VirtualHost> #配置虛擬主機 <VirtualHost *:80> DocumentRoot "d:/web2" ServerName www.ayee2.com #配置歡迎首頁面 DirectoryIndex web2.html index.html index.htm index.php <Directory /> Options FollowSymLinks #不許別人修改網站頁面 AllowOverride None #設置訪問權限 Order allow,deny Allow from all </Directory> </VirtualHost>
4.在hosts文件中添加我們的ip和主機映射關系(路徑:c:/windows/system32/drivers/etc/hosts)
在 127.0.0.1 localhost下添加如下地址
127.0.0.1 www.ayee1.com 127.0.0.1 www.ayee2.com
配置完成。
現在就可以在同一個ip下訪問兩個域名(www.ayee1.com和www.ayee2.com)站點了。