No history yet

Introduction to Web Servers

What is a Web Server?

At its core, a web server is a computer program that stores website files and delivers them to a user's web browser upon request. Think of it like a restaurant's kitchen. You (the customer) place an order with your waiter (your web browser), and the waiter takes that order to the kitchen (the web server). The kitchen prepares your meal (the webpage) and gives it back to the waiter, who then brings it to your table.

A web server stores, processes, and delivers web pages in response to user requests via HTTP.

This interaction is called the client-server model. Your browser is the client, and the computer hosting the website files is the server. When you type a URL into your browser, you're telling the client to ask a specific server for a specific file.

Lesson image

The server's job is to be available 24/7, waiting for these requests. Once a request comes in, the server finds the requested file—whether it's an HTML page, an image, or a CSS file—and sends it back across the internet to your browser. Your browser then assembles these files to display the complete webpage you see on your screen.

The Language of the Web: HTTP

Clients and servers need a shared language to understand each other. On the web, that language is the Hypertext Transfer Protocol, or HTTP. It’s a set of rules that governs how messages are formatted and transmitted between devices.

protocol

noun

A standardized set of rules that allow two or more entities in a communications system to transmit information.

This communication happens through a cycle of requests and responses. The client sends an HTTP request, and the server sends back an HTTP response. This simple back-and-forth is the foundation of every interaction you have on the web, from loading a news article to watching a video.

Requests and Responses

An HTTP request is a message from your browser to the web server, asking for a specific resource. The most important parts of a basic request are the method and the path.

  • Method: The action the client wants to perform. The most common is GET, which requests data from the server.
  • Path: The specific resource on the server, like /about-us.html.
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

When the server receives this request, it processes it and sends back an HTTP response. The response includes a status code and, usually, the resource that was requested.

  • Status Code: A three-digit code that signals the result of the request. You might have seen 404 Not Found. The code for a successful request is 200 OK.
  • Body: The actual content of the resource, such as the HTML code for a webpage.
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 1256

<!DOCTYPE html>
<html>
<head>
  <title>Example Page</title>
</head>
<body>
  <h1>Hello, World!</h1>
</body>
</html>

The browser receives this response, reads the HTML in the body, and renders the webpage for you to see. This entire exchange happens in a fraction of a second, millions of times per minute all across the globe.