What Is a Web Server?
Learn what a web server does, how browsers communicate with servers over HTTP, how URLs and ports work, and where Apache HTTP Server fits.
What Is a Web Server?
A web server is software that accepts requests for web resources and sends responses back to clients. A web resource can be an HTML page, stylesheet, JavaScript file, image, download, or API response.
The term can also refer to the computer or service running that software. More precisely, the software handles web communication, while the machine provides the network connection, storage, and processing resources it needs.
A web server commonly performs these jobs:
- Retains or accesses website files, such as HTML, CSS, JavaScript, and images.
- Receives incoming requests from browsers and other HTTP-capable applications.
- Locates a requested file or passes the request to application code.
- Generates or obtains content when necessary.
- Returns the content and information about the result to the client.
The Client-Server Model
A client is a program that asks for a resource. A web browser is the most familiar example, but command-line tools, mobile applications, and other services can also act as HTTP clients.
A server is the system or software endpoint that receives the request and sends a response. The server might be a physical computer, a virtual machine, a container, or a managed service.
| Participant | Primary Actions | Typical Example |
|---|---|---|
| Web client | Creates a request, sends it, and interprets the response. | A browser requesting a homepage |
| Web server | Receives the request, finds or generates the resource, and returns a response. | Apache returning an HTML file |
The communication usually follows this sequence:
- You enter a web address or select a link.
- The client identifies the destination and prepares an HTTP request.
- The request travels to the host and port where a web service is listening.
- The web server examines the requested resource.
- The server returns an HTTP response.
- The browser interprets the response and renders the page. It may then make additional requests for stylesheets, scripts, images, and other embedded resources.
Each request targets one resource and produces a corresponding response. A homepage request and a logo-image request are separate HTTP exchanges, even when both belong to the same page.
HTTP: The Web Delivery Protocol
HTTP, or Hypertext Transfer Protocol, is an application-layer protocol commonly used for communication between web clients and servers. HTTP uses a request-response pattern: the client sends a request, and the server sends a response.
HTTP Requests
An HTTP request asks for a resource or asks the server to perform an HTTP operation. Its important parts include:
- Method: The operation, such as
GETfor retrieving a resource orPOSTfor submitting data. - Target: The URL or path identifying the intended resource.
- Headers: Metadata such as the requested host, accepted content types, and authentication information.
- Optional body: Data sent with the request, commonly when submitting a form or sending API data.
A simplified request for a homepage could look like this:
GET / HTTP/1.1
Host: example.comThe first line says that the client wants to retrieve the / path using HTTP version 1.1. The Host header identifies the website being requested. A modern server may host several websites on the same address, so this information matters.
HTTP Responses
An HTTP response tells the client what happened. It includes:
- Status code: A numeric result, such as
200,404, or500. - Headers: Metadata such as the content type, size, caching instructions, and cookies.
- Response body: The returned content, when there is content to send.
| Outcome | Example Status | Meaning |
|---|---|---|
| Successful delivery | 200 OK | The server successfully returned the requested resource. |
| Missing content | 404 Not Found | The server was reached, but the requested path has no matching resource. |
| Server-side failure | 500 Internal Server Error | The server encountered an unexpected problem while handling the request. |
A simplified response might look like this:
HTTP/1.1 200 OK
Content-Type: text/html
<html>...</html>The headers come before the response body. The body could contain HTML, an image, JSON from an API, a stylesheet, or another representation of the requested resource.
Understanding URLs, Hosts, and Paths
A URL, or Uniform Resource Locator, is a web address. It tells a client which protocol to use, which host to contact, which optional port to use, and which resource to request.
For example:
http://example.com:80/images/logo.png| Component | Example | Purpose |
|---|---|---|
| Scheme | http | Identifies the communication protocol. |
| Hostname | example.com | Names the intended website or server destination. |
| Port | 80 | Directs traffic to a particular service on the host. |
| Path | /images/logo.png | Identifies the requested page or other resource. |
| HTTP method | GET | Specifies the operation the client wants to perform. |
| Response status | 200 OK | Reports the result after the server handles the request. |
The hostname identifies the intended destination. In a public network, a name-resolution system commonly maps that hostname to an IP address before the connection is made.
The path identifies a resource within the website. In /images/logo.png, the path suggests an image resource, so the response may contain an image rather than an HTML document.
The user-facing path does not have to be the name of a file on the server. A web server may map a path to a stored file, an application route, a database lookup, or another service. For example, /products might be handled by application code even if no file named products exists.
TCP Ports and Web Traffic
A network service listens on a numbered port. A port directs traffic arriving at a host to a particular service. TCP is a transport protocol commonly used by HTTP and HTTPS connections.
Unencrypted HTTP conventionally uses TCP port 80. When a URL uses HTTP without an explicit port, the client normally assumes port 80:
http://example.com
http://example.com:80These URLs normally target the same port when the server is configured in the conventional way. Writing :80 makes the default explicit; omitting it asks the client to apply HTTP's default.
HTTPS is HTTP protected by TLS encryption. It conventionally uses TCP port 443:
| Protocol | Typical Port | Security Characteristics | Example URL |
|---|---|---|---|
| HTTP | 80 | Not encrypted by default. | http://example.com |
| HTTPS | 443 | HTTP protected by TLS encryption. | https://example.com |
Port 80 is therefore not the port for all web traffic. The scheme and port must agree with a service that is actually listening.
Apache HTTP Server in Context
Apache HTTP Server is one implementation of web-server software. Apache can accept HTTP requests, serve configured websites, and return static resources such as HTML, CSS, JavaScript, images, and downloads.
Apache can also be configured for roles beyond direct page delivery. For example, it can operate as a reverse proxy, forwarding requests to an application server, or participate in traffic distribution. A proxy server forwards requests between clients and other servers. A load balancer distributes requests across multiple backend servers.
Apache is not the only web-server implementation, and a modern web application may contain several components. A browser, DNS service, firewall, Apache or another web server, reverse proxy, application server, database, and cache may all have different responsibilities.
For Apache installation and configuration foundations, see What Is Apache HTTP Server, Install Apache on Ubuntu, and Apache configuration files.
End-to-End Request Flow
Consider a user entering http://example.com into a browser:
- The browser reads the URL. Because the scheme is HTTP and no port is written, it uses TCP port 80 by default.
- The browser resolves the hostname to a network destination and opens a connection to the host's HTTP service.
- The browser sends an HTTP request, usually a
GETrequest for the root path,/. - The web server receives the request and uses its configuration to determine which website should handle it.
- The server locates a stored homepage or passes the request to application code that generates one.
- The server sends an HTTP response containing a status, headers, and usually an HTML body.
- The browser interprets the HTML and displays the page.
- If the HTML references a stylesheet, script, image, or other resource, the browser sends additional requests for those resources.
The direction can be summarized as:
Browser/client
| HTTP request: GET / ---------------------->
| Web server
| <---------------------- HTTP response: 200 + HTML
|
| Additional requests for CSS, scripts, images, and other assetsFor a request such as http://example.com/images/logo.png, the same process occurs, but the path identifies an image. The server may return the image file with a content type appropriate for an image instead of returning an HTML document.
Inspecting an HTTP Response
The curl command can act as a simple HTTP client. The -I option asks for response headers, which is useful for seeing the status and metadata without downloading the complete response body.
curl -I http://example.com
curl -I http://example.com:80Comparing these commands helps demonstrate that an omitted HTTP port and an explicit :80 normally refer to the same conventional service. The result can still differ if the server or network is configured unusually.
Troubleshooting Web Requests
A Page Cannot Be Reached When a Port Is Specified
- The service may not be listening on that port.
- A firewall or network policy may block the port.
- The URL may combine the wrong protocol and port.
A host can run multiple services, so the port is part of reaching the intended service.
The Server Returns 404 Not Found
- The requested path may have no matching file or application route.
- The resource may have been moved or removed.
A successful connection to a web server does not guarantee that the requested resource exists.
The Browser Reports a Connection Failure
- The web-server process may be stopped.
- The hostname may not resolve to the intended host.
- The service may be inaccessible on the expected port.
Diagnose these layers separately: name resolution, network connectivity, port reachability, and finally the HTTP response.
HTTP Works Without a Port but Not on a Nondefault Port
- The two URLs may target different listening ports.
- Only the default HTTP listener may be configured.
- The alternate port may be blocked.
Leaving a port out invokes the protocol default. Adding a port explicitly changes the destination.
Key Takeaways
- A web server accepts requests and delivers web resources to clients.
- The browser is usually the client; the system running web-server software is the server.
- HTTP communicates through requests and responses.
- A URL identifies a scheme, hostname, optional port, and resource path.
- HTTP conventionally uses TCP port 80, while HTTPS conventionally uses port 443.
- Apache HTTP Server is one web-server implementation and can serve files, work with applications, and act as a reverse proxy.
- A browser may make many resource requests to render one page.