This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
TCP/IP 连接始终与 IP 地址建立(您可以将 IP 地址视为某台计算机的地址,即使情况并非总是如此)和 (而不是物理)该地址上的端口。
通常,一个端口耦合到目标计算机上的特定进程或“服务”。有些端口号是标准化的,例如 http 为 80,smtp 为 25 等等。由于这种标准化,您通常不需要将端口号放入您的网址中。
因此,如果您说 http://www.stackoverflow.com 之类的内容,“stackoverflow.com”部分将解析为 IP 地址(在我的情况是 64.34.119.12),因为我的浏览器知道该标准,所以它尝试连接到该地址上的端口 80。因此,这与 http://www.stackoverflow.com:80 相同。
但是没有什么可以阻止进程侦听另一个端口上的 http 请求,例如 12434、4711 或 8080。通常(如您的情况),这用于调试目的,以免与已经侦听的另一个进程(例如 IIS)混合在一起同一台机器上的 80 端口。
2021 年注释:当我发表这篇文章时,我使用端口 80 作为示例,因为尽管 OP 没有指定协议,但 http 是当时常见的 Web 请求标准,而 80 是 http 的标准。现在几乎所有东西都运行在 https 上,标准端口是 443。
A TCP/IP connection is always made to an IP address (you can think of an IP-address as the address of a certain computer, even if that is not always the case) and a specific (logical, not physical) port on that address.
Usually one port is coupled to a specific process or "service" on the target computer. Some port numbers are standardized, like 80 for http, 25 for smtp and so on. Because of that standardization you usually don't need to put port numbers into your web adresses.
So if you say something like http://www.stackoverflow.com, the part "stackoverflow.com" resolves to an IP address (in my case 64.34.119.12) and because my browser knows the standard it tries to connect to port 80 on that address. Thus this is the same as http://www.stackoverflow.com:80.
But there is nothing that stops a process to listen for http requests on another port, like 12434, 4711 or 8080. Usually (as in your case) this is used for debugging purposes to not intermingle with another process (like IIS) already listening to port 80 on the same machine.
Note from 2021: When I made this post, I used port 80 as example because even though the OP didn't specify a protocol, http was the usual web request standard back then and 80 ist the standard for http. Nowadays pretty much everything runs on https and the standard port for that is 443.
localhost/web
等于localhost:80/web
或127.0.0.1:80/web
localhost:8080/web< /code> 等于
localhost:8080/web
或127.0.0.1:8080/web
localhost/web
is equal tolocalhost:80/web
OR to127.0.0.1:80/web
localhost:8080/web
is equal tolocalhost:8080/web
OR to127.0.0.1:8080/web
localhost:8080
表示您明确定位端口 8080。the
localhost:8080
means your explicitly targeting port 8080.http 使用端口 80,可以理解的是,当您输入地址时,您的互联网浏览器将自动使用该端口 - 除非您指定其他端口。现在,当您的计算机上运行 Web 服务器时,您需要以某种方式访问该服务器 - 由于端口 80 已经繁忙,您需要使用不同的端口才能成功连接到它。尽管任何开放端口都是公平的,但通常此类服务器被配置为使用端口 8080,因此在访问服务器时,您输入:
http://(协议)
本地主机(您的计算机)
:8080(端口8080)
/(指向您服务器的公共文件夹根目录的路径)
http uses port 80, and understandably, your internet browser will automatically use that port when you type in an address - unless you specify another port. Now, when running a web server on your computer, you need to access that server somehow - and since port 80 is already busy, you need to use a different port to successfully connect to it. Although any open port is fair game, usually such a server is configured to use port 8080, hence when accessing your server you type in:
http:// (protocol)
localhost (your computer)
:8080 (port 8080)
/ (path pointing to the root of the public folder of your server)
其中
其中
Where
Where
http://localhost:8080/web
:localhost ( hostname ) 是主机服务器的计算机名称或 IP 地址,例如 Glassfish、Tomcat。8080(端口)是主机服务器侦听请求的端口地址。
http://localhost/web
:localhost ( hostname ) 是主机服务器的计算机名称或 IP 地址,例如 Glassfish、Tomcat。主机服务器侦听默认端口 80。
http://localhost:8080/web
: localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat.8080 ( port ) is the address of the port on which the host server is listening for requests.
http://localhost/web
: localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat.host server listening to default port 80.