Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

in 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 HTTP GET message used for?

thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '13 at 23:05
    
Besides, you said there are several things, how about the other useful things? –  misteryes May 29 '13 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. –  Darth Android May 30 '13 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 '13 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. –  Darth Android May 31 '13 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.