VMware ESXi and vSphere Cluster Management
What Is a Web Server? How HTTP Requests and Responses Work
Learn what a web server does, how browsers use HTTP over TCP, how URLs and ports work, and how Apache serves static and dynamic content.
A web server is software that receives requests from clients, processes those requests, and delivers web resources. A resource can be an HTML page, CSS stylesheet, JavaScript file, image, document, API response, or output generated by an application.
The phrase web server can also refer informally to the computer or virtual machine running the server software. Technically, the web server is the software performing the request-and-response work. The host machine supplies the operating system, network connection, storage, and computing resources.
What Does a Web Server Do?
A web server makes resources available over a network according to web protocols, especially HTTP. Its primary responsibilities are to:
- Store or access site content.
- Accept requests from web clients.
- Determine which resource or service should handle each request.
- Return an HTTP response containing a result, metadata, and often content.
For a static file, the server can read the file and return it directly. For dynamic content, the server may forward the request to an application or invoke application logic that generates HTML or JSON for that particular request.
The Client-Server Model
The web uses a client-server model. A web client is a program that requests web resources. A browser is the most familiar example: it requests content, receives responses, and renders the result for the user.
The client initiates communication, and the server responds. One server can serve many clients at the same time, while one client can contact many servers while loading a single page. For example, a page may come from one host while its fonts, images, or API data come from other hosts.
- The user enters a URL in the browser.
- The browser identifies the hostname and locates the host, usually through DNS.
- The browser opens a network connection to the appropriate service port.
- The browser sends an HTTP request.
- The web server routes or processes the request.
- The server sends an HTTP response.
- The browser interprets the response and renders the result.
HTTP: The Web's Request-Response Protocol
HTTP means Hypertext Transfer Protocol. It defines the format and meaning of messages exchanged between web clients and servers. HTTP communication follows a request-response pattern: a client sends an HTTP request, and a server returns an HTTP response.
HTTPS is HTTP carried over TLS. TLS encrypts the connection and helps the client verify the server's identity. HTTPS does not replace the HTTP request and response model; it protects that communication while it travels across the network.
Understanding a URL
A URL, or Uniform Resource Locator, identifies how and where to request a resource. Consider this generic example:
http://example.com:80/docs/start.html?level=beginner#overview
Its parts are:
- Scheme:
httpspecifies the protocol. - Hostname:
example.comidentifies the intended host. - Port:
80identifies the network service. It is optional here because port 80 is HTTP's conventional default. - Path:
/docs/start.htmlidentifies the requested resource or route. - Query string:
?level=beginnercarries optional parameters to the server. - Fragment:
#overviewidentifies a location within the returned resource. The fragment is normally handled by the browser and is not sent to the server as part of the HTTP request.
The browser uses the hostname to find the intended server and uses the path to identify which resource to request. A path does not necessarily represent a physical file; an application can map it to generated content.
Ports and TCP
A port is a numbered network endpoint used to select a service on a host. A host can run several network services, with each service listening on one or more ports.
Plain HTTP conventionally uses TCP port 80. When port 80 is omitted from an http URL, the browser assumes it. HTTPS conventionally uses TCP port 443.
Assuming the same host and path, http://example.com and http://example.com:80 target the same default HTTP port. This does not guarantee that the service is available: a firewall, server configuration, or network policy can still block the connection.
HTTP commonly runs over TCP, or Transmission Control Protocol. At a high level, TCP provides a reliable connection for exchanging data between the browser and server. The relationship is:
URL scheme and port → TCP connection → HTTP request → HTTP response
This lesson does not require knowledge of TCP implementation details. The important idea is that the URL selects a service endpoint, TCP carries the exchange, and HTTP defines the web messages.
HTTP Requests
An HTTP request is a client message asking a server to perform an action on a resource. A request identifies the resource and can contain a method, target path, headers, and sometimes a message body.
- Method: describes the requested operation.
GETretrieves a resource. - Target path: identifies the resource, such as
/about. - Headers: provide metadata and preferences, such as the host, accepted content types, cookies, and caching information.
- Body: carries optional data, commonly with methods such as
POSTorPUT.
GET is the standard method a browser uses to retrieve a page or another resource. Other common methods include POST for submitting data, PUT for replacing or storing a resource, and DELETE for requesting removal. These methods provide context here; a complete method reference is a separate topic.
The Host header is especially important when multiple websites share one server or IP address. It tells the server which hostname the client requested, allowing the server to select the appropriate virtual host and content.
GET /about HTTP/1.1
Host: example.com
Accept: text/html
HTTP Responses
An HTTP response reports the result of a request. It contains a status code, headers, and usually a body. For a successful HTML-page request, the body contains HTML that the browser can parse and render.
- Status code: a numeric result indicator.
- Headers: metadata such as content type, content length, cookies, and caching instructions.
- Body: optional returned content, such as HTML, CSS, an image, or JSON.
HTTP/1.1 200 OK
Content-Type: text/html
<!doctype html>
<html>
<body>About this site</body>
</html>
Static Content and Dynamic Applications
Static content is returned directly as stored content. For example, a request for /images/logo.svg may cause the web server to read that file from disk and send it with an appropriate content type.
Dynamic content is created or selected after a request arrives. A request for /account might be sent to an application that checks the signed-in user and generates user-specific HTML or JSON.
A common architecture uses a reverse proxy. The browser contacts the web server, the web server forwards selected requests to an application service, and the web server relays the application's response back to the browser.
Browser → web server → application service
Browser ← web server ← application response
Apache HTTP Server
Apache HTTP Server, commonly called Apache or httpd, is web server software. It is one implementation of the web server role, not the definition of a web server itself. The general concepts of requests, responses, resources, ports, and HTTP apply regardless of which web server product is installed.
Apache can serve static files and can also provide related capabilities such as:
- TLS termination, where the server handles encrypted HTTPS connections.
- Access logging, which records requests and their outcomes.
- Virtual hosting, which allows multiple hostnames or sites to share a server.
- Reverse proxying to application services.
- Load balancing across backend servers.
Proxying and load balancing are additional roles Apache can perform beyond directly serving web pages. This conceptual lesson does not require installing Apache or configuring virtual hosts; those tasks belong in a dedicated Apache setup lesson.
End-to-End Request Lifecycle
Suppose a user enters http://example.com/ and the server has a default HTML page.
- URL parsing: The browser identifies the
httpscheme, the hostnameexample.com, and the path/. Because no port is written, it assumes TCP port 80. - DNS lookup: The browser or operating system asks the Domain Name System, or DNS, to translate the hostname into a network address.
- Connection establishment: The browser opens a TCP connection to that address on port 80.
- HTTP request: The browser sends a
GETrequest for/, including aHostheader. - Server routing and processing: The web server selects the matching site and determines whether to return a static file or forward the request to an application.
- HTTP response: The server returns a status such as
200 OK, headers such asContent-Type: text/html, and an HTML body. - Browser rendering: The browser parses the HTML and displays the page.
- Additional requests: The HTML commonly references stylesheets, scripts, fonts, and images, causing the browser to send more requests.
Troubleshooting by Symptom
- 404 Not Found: The server was reached and understood the request, but the path does not identify an available resource.
- 403 Forbidden: The server received the request but access to the resource is not allowed.
- 500 Internal Server Error: The web server or an application behind it failed while processing the request.
- A URL works on one port but not another: The service may not be listening on the second port, or a firewall or network policy may block it.
- The hostname cannot be reached: DNS resolution may have failed, the host may be unavailable, or the network connection may be interrupted.
- HTTP and HTTPS behave differently: They normally use ports 80 and 443 respectively, and HTTPS additionally requires valid TLS configuration.
Optional Browser and Command-Line Demonstrations
In a browser address bar, compare http://example.com/docs with http://example.com:80/docs. The explicit port shows the default that the first URL implies.
A command-line HTTP client can expose response headers without requiring a server setup:
curl -i http://example.com/
The -i option displays the response status line and headers along with the body. Look for a status such as 200 OK and a header such as Content-Type. This command is secondary; the key lesson is the relationship between the URL, connection, request, and response.
Key Takeaways
- A web server is software that accepts web requests and returns resources; the term can also informally mean the host running that software.
- A browser is a web client: it initiates requests, while the server returns responses.
- HTTP defines web request and response messages. HTTPS adds TLS protection.
- A URL identifies a scheme, hostname, optional port, path, query string, and optional fragment.
- HTTP conventionally uses TCP port 80, while HTTPS conventionally uses TCP port 443.
- Servers can return static files, generate or forward dynamic content, act as reverse proxies, and balance traffic.
- Apache HTTP Server is one widely used implementation of the web server role.