WEB: Introduction to Web Servers

A web server is software that listens for incoming HTTP connections and delivers web content to clients. This post covers how web servers work, the HTTP protocol, root directories, virtual hosting, and the most common web server software used in production.

Every website you visit, every API you call, and every file you download from the internet is served by a web server. Understanding how web servers work is foundational knowledge for any backend developer or systems engineer.


What is a Web Server?

A web server is software that:

  1. Listens for incoming network connections on a port (usually port 80 for HTTP, 443 for HTTPS)
  2. Accepts requests using the HTTP protocol
  3. Delivers the requested content (HTML, CSS, JavaScript, images, API responses) back to the client

md
+----------------+          HTTP Request          +------------------+
|                | -----------------------------> |                  |
|     Client     |                                |    Web Server    |
|   (Browser)    | <----------------------------- |                  |
+----------------+          HTTP Response         +------------------+
                                                          |
                                                          v
                                                  +------------------+
                                                  |  File System /   |
                                                  |  Application     |
                                                  +------------------+

The client (browser, mobile app, or another service) sends a request, and the web server reads the request, retrieves the appropriate content, and sends back a response.


The HTTP Protocol

The HTTP (HyperText Transfer Protocol) is the foundation of data communication on the web. It defines how requests and responses are formatted.

HTTP Request Structure

md
GET /picture.jpg HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: image/jpeg

HTTP Response Structure

md
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 34512

[binary image data...]

Common HTTP Methods

MethodDescription
GETRetrieve a resource
POSTSubmit data to be processed
PUTReplace a resource completely
PATCHPartially update a resource
DELETERemove a resource

Common HTTP Status Codes

CodeMeaning
200 OKRequest succeeded
301 Moved PermanentlyResource has been permanently moved
302 FoundTemporary redirect
400 Bad RequestClient sent a malformed request
401 UnauthorizedAuthentication required
403 ForbiddenAccess denied
404 Not FoundResource does not exist
500 Internal Server ErrorServer-side error

The Root Directory

A web server delivers files from a configured root directory (also called the document root). This is the folder on the server's file system that maps to the root URL (/).

md
URL Request:     http://www.example.com/picture.jpg
                                              |
                                              v
Server maps to:  /var/www/html/picture.jpg

Default Root Directories

Web ServerDefault Root Directory (Linux)Windows
Apache/var/www/htmlC:\Apache24\htdocs
Nginx/var/www/html
IISC:\inetpub\wwwroot

The root directory is configurable in the web server's configuration files. You can change it to any path on the file system.


Virtual Hosts

A single web server can host multiple websites with different domain names using a feature called Virtual Hosts.

When a request arrives, the web server reads the Host header from the HTTP request and compares it against its virtual host configurations. It then serves files from the matching virtual host's root directory.

md
HTTP Request 1: Host: one.com
    --> Web Server checks virtual hosts
    --> Matches one.com
    --> Serves files from /var/www/website_one

HTTP Request 2: Host: two.com
    --> Web Server checks virtual hosts
    --> Matches two.com
    --> Serves files from /var/www/website_two

HTTP Request 3: Host: unknown.com
    --> Web Server checks virtual hosts
    --> No match found
    --> Serves the default website

Apache Virtual Host Configuration Example

bash
<VirtualHost *:80>
    ServerName one.com
    DocumentRoot /var/www/website_one
    ErrorLog /var/log/apache2/one.com-error.log
</VirtualHost>

<VirtualHost *:80>
    ServerName two.com
    DocumentRoot /var/www/website_two
    ErrorLog /var/log/apache2/two.com-error.log
</VirtualHost>

Nginx Server Block Example

bash
server {
    listen 80;
    server_name one.com;
    root /var/www/website_one;
}

server {
    listen 80;
    server_name two.com;
    root /var/www/website_two;
}

There is no limit to the number of virtual hosts you can configure on a single server.


Common Web Server Software

SoftwareDescriptionBest For
Apache HTTP ServerThe most widely deployed web server, highly configurable via .htaccessShared hosting, PHP applications
NginxHigh-performance, event-driven architecture, excellent as reverse proxyHigh-traffic sites, reverse proxy, load balancing
IIS (Internet Information Services)Microsoft's web server, integrated with Windows ServerWindows/.NET environments
Node.js (http module)JavaScript-based HTTP server, often used with ExpressNode.js applications, APIs
CaddyModern server with automatic HTTPSSimple deployments, development

Static vs Dynamic Content

Web servers handle two types of content differently:

md
+--------------------------------------------------+
|              Web Server                          |
|                                                  |
|  Static Content           Dynamic Content        |
|  (served directly)        (processed first)      |
|                                                  |
|  HTML files               PHP scripts            |
|  CSS files                Python (WSGI/ASGI)     |
|  Images                   Node.js applications   |
|  JavaScript files         Ruby on Rails          |
+--------------------------------------------------+

Static content is served directly from the file system with no processing.

Dynamic content is processed by an application server (PHP-FPM, Gunicorn, Node.js) and the web server acts as a reverse proxy, forwarding requests to the application and relaying responses back to the client.


Reverse Proxy Architecture

In production environments, web servers like Nginx are often used as reverse proxies in front of application servers:

md
Client
  |
  v
Nginx (reverse proxy)
  |
  +-- /api/*   --> Node.js app on port 3000
  |
  +-- /static  --> /var/www/static (static files)
  |
  +-- /*       --> Python/Django app on port 8000

Benefits of this architecture:

  • SSL termination: Nginx handles HTTPS, backend speaks plain HTTP
  • Load balancing: distribute requests across multiple app instances
  • Caching: serve cached responses without hitting the application
  • Security: hide backend services from direct internet exposure
  • Compression: gzip compress responses before sending

HTTPS and SSL/TLS

Modern web servers must serve content over HTTPS (HTTP Secure). HTTPS encrypts the connection between client and server using TLS (Transport Layer Security).

md
Client                              Web Server
  |                                    |
  |   TLS Handshake                    |
  | ---------------------------------> |
  | <--------------------------------- |
  |   Certificate + Public Key         |
  |                                    |
  |   Encrypted Communication          |
  | <================================> |

To enable HTTPS you need:

  1. A TLS certificate (from a Certificate Authority like Let's Encrypt)
  2. Configure the web server to use port 443 and load the certificate

bash
# Nginx HTTPS configuration
server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    root /var/www/html;
}


Web Server Performance Concepts

ConceptDescription
ConcurrencyHow many simultaneous connections the server can handle
ThroughputRequests per second the server can process
LatencyTime from request to first byte of response
CachingStoring responses to avoid repeated processing
CompressionReducing response size with gzip or Brotli
Keep-AliveReusing TCP connections across multiple requests

Final Thoughts

Web servers are the entry point for all web traffic. Whether you are serving static files, running a dynamic application, or building a microservices architecture, the web server is the component that listens, routes, and responds to every single request.

Understanding how root directories, virtual hosts, reverse proxies, and HTTPS work gives you the foundation to configure, optimize, and troubleshoot any web server environment.

The web server is the front door of everything you build.