2

In an HTTP GET message, there is a HOST field:

Host.
The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. The port number may be omitted if the port is the standard port for the service requested.

In this field, there is a port number. I know that port number is on the transport layer. So what is the port number in an HTTP GET message used for?

1

1 Answer 1

3

It's useful for several things, one of which is for generating URLs in proxies. I might have nginx configured as a load-balancing proxy on port 80, while the actual HTTP server is running on port 7790. If the web server needs to create an absolute URL back to itself, it can't use the transport layer information, because that'll just give it the internal network info. It needs to look at the HTTP headers to know what the real client is and how they are accessing the server to generate the URLs.

5
  • I understand the first 2 sentences. I don't understand :If the web server needs to create an absolute URL back to itself, it can't use the transport layer information, because that'll just give it the internal network info. It needs to look at the HTTP headers to know what the real client is and how they are accessing the server to generate the URLs. can you make it more clear? thanks
    – misteryes
    May 29, 2013 at 23:05
  • Besides, you said there are several things, how about the other useful things?
    – misteryes
    May 29, 2013 at 23:05
  • @misteryes If the client is connecting to http://ex.com:8080, and that connection is being load-balanced over 3 webservers (int.ex.com:7001, int.ex.com:7002, and int.ex.com:7003), then the webservers can't look at the transport layer to find out the port, because it will be incorrect. If a php script wants to write a link into a page, it can't just use http://int.ex.com:7001/somelink. It needs to use the Host field to do this, so that when the client clicks on it, they go to the correct url. May 30, 2013 at 16:56
  • so the TCP connection is just between the client and ex.com:80, there is no TCP connection between the client and ex.com:7001, ex.com:7002, is it right?
    – misteryes
    May 31, 2013 at 15:49
  • Correct. There is a connection from the load balancer (on ex.com:80) and ex.com:7001, but not directly from the client to ex.com:7001. And most of the time, web pages use relative hyperlinks, so knowing the host/port is not a common issue, but it could be potentially. A much more common scenario is having the loadbalancer or proxy set the X-HTTPS header, indicating if the client connected with https or not. Same concept- the webserver doesn't get to see the real client connection, so the proxy or load balancer has to make sure that the HTTP headers contain all of that information. May 31, 2013 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .