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

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

问题描述

我将 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/

但是,这个地址不起作用.

But, this address does not work.

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.更改 如下:

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 可以访问这个 url.

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

这是一个临时更改,一旦您重新启动它就会恢复.如果你想让它永久,你可以为它创建一个 lauch deamon.

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 创建了一个不错的指南来展示如何使用 设置从端口 80 到另一个端口的端口转发pfctl.

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 绑定并添加一个新的绑定,这样您就可以使用给定的 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 地址而不是本地主机浏览网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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