Why do we need to specify a port number while using HTTP protocol?

前端 未结 2 656
闹比i
闹比i 2021-02-05 22:01

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 alrea

相关标签:
2条回答
  • 2021-02-05 22:49

    A port is like a "channel" in a way... If you have to access different functions of the same website, you use different ports. HTTP is port 80, HTTPS is 443, SSH is 22, and so on.

    0 讨论(0)
  • 2021-02-05 23:02

    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.

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

    <scheme>://<host>:<port>/<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.

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

    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.

    0 讨论(0)
提交回复
热议问题