eclipse 尝试使用 IP 地址而不是本地主机访问页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17069395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:43:05  来源:igfitidea点击:

Attempting to access page using IP address instead of localhost

eclipsetomcatlocalhosttomcat7

提问by Keshava Murthy

I was working through the following tutorial: http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

我正在完成以下教程:http: //www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

And I've managed to get it working. I can type in

我已经设法让它发挥作用。我可以输入

http://localhost/test-app/ 

and it displays (on my computer obviously) exactly what I want to see. (Which is, of course, fantastic.)

它显示(显然在我的电脑上)正是我想看到的。(当然,这太棒了。)

However, I'm now looking to port this out so that I can view that same page from other computers. I know I need to be on the same network, and I am, but I can't figure out how to see that page. I've tried using:

但是,我现在希望将其移植出来,以便我可以从其他计算机查看同一页面。我知道我需要在同一个网络上,我是,但我不知道如何查看该页面。我试过使用:

My IP address is 155.198.X.X and I'm using port 80.

我的 IP 地址是 155.198.XX,我使用的是端口 80。

http://155.198.X.X/test-app (didn't work)
http://155.198.X.X:80/test-app (didn't work either)

These don't work on either my computer or other computers on the same network.

这些不适用于我的计算机或同一网络上的其他计算机。

I'm using Tomcat 7.0 and Eclipse for my code.

我的代码使用 Tomcat 7.0 和 Eclipse。

Am I missing something?

我错过了什么吗?

Cheers, Kesh

干杯,凯什

EDIT:

编辑:

I'm starting to think that it's something to do with when I tried earlier to set up a server. I did another tutorial. Basically, every time I put my web server's IP address in to a computer, the following text appears: "It works!".

我开始认为这与我之前尝试设置服务器时有关。我做了另一个教程。基本上,每次我将网络服务器的 IP 地址输入计算机时,都会出现以下文本:“It works!”。

Sample

样本

Does this have anything to do with it?

这与它有什么关系吗?

采纳答案by Russell Uhl

Ah! New data!

啊! 新数据!

You posted a screenshot, and you mentioned you tried to set up another web server using a different tutorial. Well, it WORKED. The "It Works!" page is the standard go-to page for apache servers, and I would assume others. It exists to tell you that you have, in fact, successfully set up a web server.

您发布了一个屏幕截图,并提到您尝试使用不同的教程设置另一个 Web 服务器。好吧,它奏效了。“它有效!” page 是 apache 服务器的标准转到页面,我会假设其他人。它的存在是为了告诉您,您实际上已经成功地设置了一个 Web 服务器。

So:

所以:

My guess is that the problem lies in a config file. Since you stated that it DOES work with localhost, it would appear that there is some redirecting happening. If the traffic is coming internally from the machine, then it displays what you want. If the traffic is from elsewhere, however, it redirects to the "itworks" page.

我的猜测是问题出在配置文件中。由于您声明它确实适用于本地主机,因此似乎发生了一些重定向。如果流量来自机器内部,那么它会显示您想要的内容。但是,如果流量来自其他地方,则会重定向到“itworks”页面。

A thought occurs to me. Is it possible you currently have TWO web servers running right now? If you do, they are on separate ports, so you will have to adjust your url (and various program settings, etc) accordingly.

我想到了一个想法。您目前是否有可能正在运行两个 Web 服务器?如果这样做,它们位于不同的端口上,因此您必须相应地调整您的 url(以及各种程序设置等)。

Edit(from comments): Make sure that you are only running one web server at a time when you first start off. If you have more than one running, it can be difficult to determine which one you are targeting. Leave your code alone until you make sure only one instance of one webserver is running, and that it is configured enough for you to get the "It works" page up. THEN worry about code. Otherwise, your code may be perfect.....just being targeted by the webserver you don't know about.

编辑(来自评论):确保您在第一次启动时一次只运行一个 Web 服务器。如果您有不止一位跑步者,则可能很难确定您的目标是哪一位。不用管你的代码,直到你确保只有一个网络服务器的一个实例正在运行,并且它的配置足以让你打开“它可以工作”页面。然后担心代码。否则,您的代码可能是完美的......只是被您不知道的网络服务器定位。

回答by RedBrogdon

Your machine may have a firewall installed that's blocking the traffic from the other computers.

您的机器可能安装了防火墙,阻止来自其他计算机的流量。

If you're running Windows, for example, try opening the "Windows Firewall" item in the control panel and creating a rule to allow inbound traffic on port 80.

例如,如果您运行的是 Windows,请尝试打开控制面板中的“Windows 防火墙”项并创建规则以允许端口 80 上的入站流量。