Skip to content

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:

Host: <hostname>[:port]

Examples:

Host: example.com
Host: example.com:8080

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:

GET /index.html HTTP/1.1
Host: example.com

In this example:

  • The Host header tells the server to serve example.com's content.
  • The request method is GET, asking for index.html.

HTTP Request with Non-Standard Port:

GET /api/data HTTP/1.1
Host: example.com:8080

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:

GET /home HTTP/1.1
Host: blog.example.com

In this case:

  • The request is specifically for blog.example.com, which might be different from www.example.com.
  • The server can serve different content based on the Host header.