无法在本地计算机上浏览在家中托管的网站

发布于 2024-07-15 05:49:47 字数 116 浏览 5 评论 0原文

我在家里有一个 IIS 上托管的 ASP.NET 网站。 在我的家庭网络之外我可以看到该网站,但在网络内部它给我一个 404 错误。 我可以作为本地主机浏览该网站。 看起来像是 DNS 问题,只是不知道如何解决。

I have an ASP.NET website hosted at home on IIS. Outside my home network i can see the website, but inside the network it gives me a 404 error. I can browse the site as localhost. It seems like a DNS problem, just not sure how to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2024-07-22 05:49:47

这几乎肯定是 NAT 问题。 我假设您的 Web 服务器位于 NAT 路由器后面,并且您已将某个端口(可能是 80)从路由器的外部接口转发到服务器计算机上的端口 80。 我还假设您尝试使用解析为外部 IP 的名称(可能是动态 DNS 名称)来访问您的网站,或者尝试使用该外部 IP 直接访问它。 这可能无法开箱即用,因为大多数 NAT 路由器只会为进入路由器外部接口的数据包提供端口映射。

如果上述情况成立,则有四种可能的解决方案:

  1. 查看路由器的配置并尝试找到类似于“NAT 环回”、“Ext-int 环回”等的内容。 这将指示路由器处理从内部接口传入并发往外部 IP 的数据包,就像处理从外部接口传入的数据包一样,从而有效地正确地环回流量。 这将触发端口转发,您的站点将正常工作。 并非所有路由器都有此选项,但如果您的路由器有,这将是最强大的解决方案。 如果你的没有,你也可以尝试将其固件更改为支持你的路由器的免费固件之一(Tomato、OpenWRT、DD-WRT 等),我使用过 Tomato 成功应对此类情况。

  2. 当您在路由器后面时使用内部 IP,在室外时使用外部 IP。

  3. 将您使用的 DNS 名称添加到您自己的主机文件中,使其与内部 IP 相对应。 当从您自己的主机访问名称时,这将自动实现(3)。 您必须对路由器后面的每个主机重复此操作。

  4. 在路由器后面运行您自己的 DNS 服务器,使其声明对您的 DNS 记录的权限并将其解析为内部 IP,同时将其他 DNS 查询转发到您的实际名称服务器。

That's almost certainly a NAT problem. I assume your web server sits behind a NAT router and you've forwarded some port (probably 80) from the external interface of the router to port 80 on your server machine. I also assume you're trying to access your website either using a name which resolves to your external IP (probably a dynamic DNS name), or you're trying to access it directly using that external IP. This will probably not work out of the box since most NAT routers will only make the port mapping available for packets coming in on the router's external interface.

If the above holds true, there are four possible solutions:

  1. Look at your router's configuration and try to find something akin to "NAT loopback", "Ext-int loopback" or the like. That will instruct the router to handle packets coming in from the internal interface and destined for the external IP just as it would handle packets coming in from the external interface, effectively correctly looping back the traffic. That will trigger the port forwarding and your site will work. Not all routers have this option, but if yours does it would be the most robust solution. If yours doesn't, you could also try to change its firmware to one of the free ones out there which supports your router (Tomato, OpenWRT, DD-WRT, etc.) I've used Tomato successfully for such scenarios.

  2. Use the internal IP when you're behind the router and the external one when outside.

  3. Add the DNS name you're using to your own hosts file making it correspond to the internal IP. This will achieve (3) automatically when accessing the name from your own host. You will have to repeat this for every single host behind your router.

  4. Run your own DNS server behind the router, make it claim authority over your DNS record and resolve it to the internal IP, while forwarding the other DNS queries to your actual name server.

秋日私语 2024-07-22 05:49:47

您可能将域指向的外部可见 IP 地址实际上是您的路由器或电缆调制解调器的 IP 地址。 外部连接将被路由到启用了 IIS 的计算机,但是当您从网络内部连接时,您将获得路由器自己的 Web 服务器及其管理界面。 这不太可能有与您请求的 URL 匹配的页面,因此您将收到 404。

您应该能够通过向家用计算机的主机文件添加一个条目以将您的域映射到计算机的内部 IP 来修复它启用 IIS,覆盖 DNS 条目中的外部 IP。

The externally visible IP address that you've presumably pointed your domain to is really the IP address of your router or cable modem. External connections will be routed to the machine with IIS on, but when you connect from inside the network you'll get the router's own web server with its admin interface. That's unlikely to have a page matching the URL you requested, so you'll get a 404.

You should be able to fix it by adding an entry to the hosts files of your home machines to map your domain to the internal IP of the machine with IIS on, overriding the external IP in the DNS entry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文