为什么在使用HTTP协议时需要指定端口号? [英] Why do we need to specify a port number while using HTTP protocol?

查看:1000
本文介绍了为什么在使用HTTP协议时需要指定端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使使用HTTP协议,为什么还要用IP地址指定端口号?例如-http://xyz:8080...-这甚至意味着什么?我们已经知道,使用HTTP时,请求将在端口80处得到服务,为什么我们要显式指定端口?

Why do we need to specify a port number with an IP address even if we are using HTTP protocol? For example - http://xyz:8080... - what does this even mean? We already know that while using HTTP the request will be served at port 80, so why do we specify a port explicitly?

推荐答案

HTTP的默认端口是80,HTTPS是443,但是端口号的范围是0到65535.大多数Web服务器都在默认端口上进行侦听,因此引用起来更简单到不带端口的URL.例如,由于端口80是默认端口,因此http://www.cnn.com/引用与http://www.cnn.com:80/相同的资源.如果HTTP/HTTPS服务不是默认端口,则必须在URL中指定该端口.

The default port for HTTP is 80 and HTTPS is 443 but port numbers range from 0 to 65535. Most web servers listen on the default port so it's simpler to refer to the URL without the port. For example, http://www.cnn.com/ refers to the same resource as http://www.cnn.com:80/ since port 80 is the default port. If a HTTP/HTTPS service is other than the default port then the port must be specified in the URL.

URL由 RFC 1738 定义,其简化语法包括端口:

The URL is defined by RFC 1738 with this simplified syntax which includes the port:

<scheme>://<host>:<port>/<url-path>

因此,例如,URL http://xyz:8080/...指的是侦听使用HTTP作为协议的端口8080的主机名或IP地址.然后,该地址处的HTTP(或Web)服务器将 url-path 解析为特定的服务或文件.

So for example, the URL http://xyz:8080/... refers to a host machine name or IP address listening to port 8080 with HTTP as the protocol. The HTTP (or web) server at that address then resolves the url-path to the particular service or file.

当端口是给定方案或协议(例如HTTP = 80)的默认端口时,该端口是可选的.

The port is optional when it is the default port for the given scheme or protocol (e.g., HTTP=80).

一台给定的计算机可以承载来自不同端口的具有HTTP服务的多个不同产品.例如,Apache Web服务器正在侦听给定服务器上的端口80,而Apache Tomcat正在侦听同一台计算机上的端口8080.各种数据库和消息传递产品通常在不同的端口上具有HTTP服务. 端口是地址的一部分,客户可以从该地址引用特定的服务.

A given machine can host multiple different products with HTTP services from different ports. For example, Apache web server is listening to port 80 on a given server while Apache Tomcat is listening to port 8080 on the same machine. Various database and messaging products typically have HTTP services on different ports. The port is part of the address from which a client can reference a specific service.

这篇关于为什么在使用HTTP协议时需要指定端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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