Host
Description
The Host request header specifies the domain name of the server that is being
requested. It is a mandatory header in HTTP/1.1 and later, allowing a single
server to host multiple domains (virtual hosting). The server uses the Host
header to determine which website or resource should handle the request.
In addition to specifying the domain, the Host header may include an optional
port number when the request is directed to a non-standard port.
Example use cases:
- Identifying which website to serve when multiple domains are hosted on the same IP.
- Ensuring requests are directed to the correct port when necessary.
- Supporting virtual hosting environments where multiple services operate on a single IP.
Syntax
The Host header follows this structure:
Examples:
The first example specifies the domain without a port, meaning the default port (80 for HTTP, 443 for HTTPS) will be used. The second example explicitly includes a port number.
Examples
Basic HTTP Request Example:
In this example:
- The
Hostheader tells the server to serveexample.com's content. - The request method is
GET, asking forindex.html.
HTTP Request with Non-Standard Port:
Here:
- The Host header directs the request to example.com on port 8080.
- This is useful when hosting an API or other services on a non-default port.
Virtual Hosting Example:
In this case:
- The request is specifically for
blog.example.com, which might be different fromwww.example.com. - The server can serve different content based on the
Hostheader.