简介:这是如何使用apache在本地服务器虚拟域名来测试网站的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=327015' scrolling='no'> 能实现效果就行,直接用xampp的最好方法就是省事,不用一个一个软件安装!然后下面一步一步实现虚拟一个www.123.com来访问本地网站程序。1.关闭xampp的apache,然后找到C:\xampp\apache\conf\extra\httpd-vhosts.conf文件:
在##NameVirtualHost *:80 下面加入以下代码,其中的IP为本地电脑的IP,可以进入CMD使用ipconfig查询到本机IP
NameVirtualHost 192.168.1.101:80
然后把以下代码复制一份
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>
修改成以下代码
<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "E:/php/ecshop2.72"
ServerName www.123.com
ServerAlias www.123.com
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
其中DocumentRoot 是本机网站制作程序的路径,ServerName及ServerAlias 就是要虚拟的域名网址,这个随便你高兴了
2.找到C:\xampp\apache\conf\httpd.conf文件,找到以下代码:
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
把上面的两个网站目录的路径修改成上面设置的路径
DocumentRoot "E:/php"
<Directory "E:/php">
因为设置了虚拟的域名网址,所以路径不用再加上网站的文件夹名称了
3.然后打开C:\WINDOWS\system32\drivers\etc\hosts 文件,
在127.0.0.1 localhost下添加你要添加的虚拟域名网址
127.0.0.1 localhost
192.168.1.101 www.123.com