配置Apache虚拟主机(VirtualHost)目的
让本地的测试环境使用多个域名,同时可以使用不同的网站根目录,有几个域名需要共用一个相同的网站根目录。
如果我们想要在本机把url
http://localhost/icash365.com/webroot/
配置为url
http://test-icash365.com/
方法如下:
1.修改D:\xampp\apache\conf\httpd.conf文件
在“Listen 80”下(或在末尾适当位置)添加如下代码
2.修改C:\WINDOWS\system32\drivers\etc\hosts文件
代码改为
3.重启apache即可
参考[url]http://clin003.com/servers/windows-configure-apache-virtualhost-1850/[/url]
让本地的测试环境使用多个域名,同时可以使用不同的网站根目录,有几个域名需要共用一个相同的网站根目录。
假设
xampp安装路径为
D:\xampp\
web根目录为
D:\xampp\htdocs\
当前根目录文件夹结构为
D:\xampp\htdocs\
D:\xampp\htdocs\cakephp
D:\xampp\htdocs\icash365.com\webroot
...
则访问这些目录的url为
http://localhost/
http://localhost/cakephp/
http://localhost/icash365.com/webroot/
如果我们想要在本机把url
http://localhost/icash365.com/webroot/
配置为url
http://test-icash365.com/
方法如下:
1.修改D:\xampp\apache\conf\httpd.conf文件
在“Listen 80”下(或在末尾适当位置)添加如下代码
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\xampp\htdocs\icash365.com\webroot"
ServerName test-icash365.com
#若有多个域名需要共用一个目录
#ServerAlias test-icash365.com icash365-test.com
</VirtualHost>
2.修改C:\WINDOWS\system32\drivers\etc\hosts文件
代码改为
127.0.0.1 localhost
127.0.0.1 test-icash365.com
3.重启apache即可
参考[url]http://clin003.com/servers/windows-configure-apache-virtualhost-1850/[/url]