本地调试多个网站,每个网站一个域名的方法
在本地架构iis进行调试程序时,大家可能都遇到一个相同的问题:就是在本地进行调试的时候,除了那个 localhost,就不能再建一个网站了,IIS会提示80端口已经被占用。但有的系统又必须要在根目录下才能运行,建立虚拟目录不可行,有的人会说新 建一个新网站,改一下网站默认端口就行了。比如8080,...但这样感觉太别扭,总在目录后加一个端口,感觉不舒服,有什么办法能实现不改端口,也能新 建新的网站,而且不起冲突呢?
首先停止IIS。方法,在运行菜单输入 cmd >> net stop iisadmin >> net stop w3svc
第二步:打开C:\WINDOWS\system32\drivers\etc\hosts目录,找到hosts文件。用记事本打开,大概内容如下:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host (振海网:WWW.ZHENH.COM)
127.0.0.1 localhost
在这里我们可以加入以下代码:
127.0.0.1 localhost
127.0.0.1 www.zhenh.com
127.0.0.1 www.baidu.com
.....
后面的几行是你想新建的网站的主机头名称。可以是域名,也可以是一个名称(和虚拟目录里面的名称差不多)。
最后保存此文件。(如有防火墙或杀毒提示,选择通过)
第三步:重启IIS。方法: cmd >> net start w3svc
最后:在IIS下新建网站。主机头设为 www.zhenh.com或www.baidu.com。。。(与刚才Hosts文件里设置的一致)这样就可以 了.
以后你想在自己的电脑上加多少个网站都行了,不再在后面加烦人的端口了。