使用IP地址而不是localhost浏览网站 [英] Browse Web Site With IP Address Rather than localhost

查看:217
本文介绍了使用IP地址而不是localhost浏览网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将VS2012与IIS Express一起使用,并且似乎无法使用我的IP地址浏览我的网站.有什么办法吗?过去,它可以在VS的早期版本中正常工作.

I am using VS2012 with IIS Express and can not seem to browse my web sites using my IP Address. Is there some way to do that? It used to work fine with earlier versions of VS.

例如,此地址可以正常工作:

For example, this address works fine:

http://localhost:64651/

但是,此地址无效.

http://192.168.252.165:64651/

我可以确定IP地址,因为我只是通过ipconfig获得的.

I am sure of the IP Address, since I just got it using ipconfig.

推荐答案

转到您的IISExpress>Config文件夹,找到applicationhost.config.更改<bindings>如下:

Go to your IISExpress>Config folder, locate applicationhost.config. Change <bindings> as below:

<bindings>
      <binding protocol="http" bindingInformation="*:1407:YOUR_IP_ADDRESS" />
</bindings>

在执行此操作之前,您将必须使用netsh命令注册此IP地址,如下所示:

Before you do this , you will have to register this IP address using netsh command as below:

Windows 7中的端口转发

如果您运行的是Windows 7,则几乎所有传入连接都被锁定,因此您需要专门允许传入连接到您的应用程序.首先,启动管理命令提示符.其次,运行以下命令,将192.168.1.11:1234替换为您使用的IP和端口:

If you’re running Windows 7, pretty much all incoming connections are locked down, so you need to specifically allow incoming connections to your application. First, start an administrative command prompt. Second, run these commands, replacing 192.168.1.11:1234 with whatever IP and port you are using:

> netsh http add urlacl url=http://192.168.1.11:1234/ user=everyone

这只是告诉http.sys与该网址对话是可以的.

This just tells http.sys that it’s ok to talk to this url.

重要信息:必须根据系统语言指定user = everyone参数.因此,如果您的Windows语言是西班牙语,则该参数必须为user = todos.

IMPORTANT: The user=everyone parameter must be specified according to the system language. So if your windows language is spanish the parameter must be user=todos.

> netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=1234 profile=private remoteip=localsubnet action=allow

这在Windows防火墙中添加了一条规则,允许本地子网中的计算机的传入连接到端口58938.有关详细信息,请参见

This adds a rule in the Windows Firewall, allowing incoming connections to port 58938 for computers on your local subnet.More information at this link.

端口转发Mac OS X

第1步:查看当前的防火墙规则

Step 1: View Current Firewall Rules

sudo ipfw show

第2步:添加端口转发规则(80至8080)

Step 2: Add Port Forwarding Rule (80 to 8080)

Tomcat运行的默认端口是8080,因此我们在此处显示将端口从80转向8080(Tomcat的默认端口)的命令.显然,这也适用于其他端口,您只需要相应地调整命令即可.

The default port that Tomcat runs on is 8080, so here we show the command to do port fowarding from port 80 to 8080 (Tomcat’s default port). Obviously, this works for other ports as well, and you’d just have to adjust the command accordingly.

sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

这是一个临时更改,重新启动后将还原.如果要使其永久存在,可以为其创建劳克恶魔.

This is a temporary change, and it will revert once you reboot. If you want to make it permanent, you can create a lauch deamon for it.

可选的删除规则

如果要删除防火墙规则,请运行:

If you want to remove your firewall rules run:

sudo ipfw flush

在Mac OS X上使用PFCTL(又名PF)进行端口转发

pfctl的设置类似于ipfw. Github用户kujon创建了尼斯指南,以展示如何使用pfctl设置从端口80到另一个端口的端口转发

The setup for pfctl is similar to ipfw. Github user kujon has created a nice guide to show how to set up port forwarding from port 80 to another port using pfctl.

注意:请确保仅通过查找项目名称来更改项目的绑定.您甚至可以保留localhost绑定并添加一个新的localhost,这样您就可以使用给定的IP地址和旧的localhost绑定访问同一网页.

Note: Be sure to change the bindings of your project only by locating its name. You can even keep the localhost binding and add a new one , this way you can access same webpage using both the given IP address and your old localhost binding.

这篇关于使用IP地址而不是localhost浏览网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆