0% found this document useful (0 votes)
12 views20 pages

Web Server - Codelivly

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views20 pages

Web Server - Codelivly

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Part I: Introduction to Web

Servers
2

1. Understanding Web Servers


Let’s kick things off with the heart of the internet: the web server. Whether you're
streaming a video, shopping online, or just reading this page, a web server is working
behind the scenes to make it happen.

But what exactly is a web server? Think of it as a digital butler. When you ask for a
webpage—by clicking a link or typing in a URL—the server jumps into action, fetches the
content you asked for, and serves it back to your browser. Fast, silent, and mostly
invisible.

Despite their quiet presence, web servers do a ton of heavy lifting. They handle
requests, serve up websites, enforce security, and connect with databases and APIs.
They're the gatekeepers of the web—making sure the right content gets to the right
people, at the right time.

In this chapter, we’ll peel back the curtain and explore:

● What web servers are and how they work,


● How the client-server model powers the web,
● The journey of web servers from the early days to the cloud era,
● And where they fit into the modern web stack.

Whether you're a developer, sysadmin, or just a curious tech enthusiast—this is where


the story begins.
3

1.1 Definition and Core Functions


Let’s dig a little deeper into what a web server actually is—not just in theory, but in
practice too.

At its most basic level, a web server is a special kind of software (and sometimes
hardware too) that delivers web pages to people’s browsers when they ask for them.

Let’s say you go to your browser and type:

<https://www.example.com>

What you’re really doing is sending a request across the internet that says:

“Hey, can you show me the homepage of example.com?”

A web server receives that request, finds the right file on the server (usually something
like index.html), and sends it back to your browser so it can display the page.

⚙ How Does It Work Behind the Scenes?


Here’s a quick step-by-step of what typically happens:

1. You (the client) request a page (say, example.com/about).


2. The Domain Name System (DNS) translates that address into an IP address
(something like 192.168.1.1)—which is basically the “home address” of the
web server.
3. Your request hits that server.
4. The web server software (like Apache or Nginx) receives the request and checks
what you’re asking for.
5. If it finds the file (like about.html), it sends it back to you. If not, you might get
a 404 error page.
6. Your browser takes the response, renders it, and shows you a beautiful webpage.
4

Behind all of this is a protocol called HTTP (HyperText Transfer Protocol), which defines
how these messages are structured and how the server and client should talk to each
other.

💡 Web Server = Software + Hardware (Sometimes)


People often confuse web servers with physical machines. Here's the clarification:

● A web server software is something like Apache, Nginx, or IIS. It runs on an


operating system and handles web requests.
● A web server machine (hardware) is the computer or virtual machine (VM/cloud
server) that hosts the software.

You can run multiple web server applications on a single machine—or just one.

🔧 Core Functions of a Web Server


Let’s look at the main jobs a web server handles. These are the everyday tasks it
performs to keep websites up and running smoothly.

1. Handling Requests and Sending Responses

The #1 job: accept incoming requests from browsers and respond with the correct
content—like HTML pages, images, CSS stylesheets, or JSON data.

2. Serving Static and Dynamic Content

● Static content = files that don’t change (HTML, CSS, images).


● Dynamic content = generated on-the-fly (e.g., user dashboards, personalized
news feeds).

Dynamic responses usually involve backend languages like PHP, Python, Node.js, etc.
The web server either processes it or forwards the request to another service to
generate the output.

3. Managing Resources

Web servers are smart enough to handle multiple users at once, manage traffic
efficiently, and make sure nobody hogs all the bandwidth. They often support
5

multi-threading or event-based models to handle hundreds or thousands of users at


the same time.

4. Supporting Security Protocols

When you see the little lock 🔒 icon in your browser, that's thanks to HTTPS, which is
HTTP + SSL/TLS encryption. The web server plays a big role in setting this up by:

● Installing SSL certificates


● Encrypting communications
● Enforcing secure headers and policies

5. Logging and Monitoring

Every request that hits the server is logged. This is useful for:

● Debugging problems (why did the site crash?),


● Security analysis (is someone trying to hack us?),
● Performance tuning (are some pages taking too long?).

Logs are usually stored in files like access.log and error.log.

6. URL Routing and Redirects

Web servers can control what happens when users visit different URLs. For example:

● Redirecting http://example.com to https://www.example.com


● Rewriting URLs for SEO-friendly links
● Blocking access to certain files or folders

7. Proxying and Load Balancing (Advanced)

In more complex setups, web servers can act as reverse proxies—sitting in front of
application servers and forwarding requests. They can also distribute traffic across
multiple backend servers, which improves performance and reliability.

🧁 Real-Life Analogy: A Restaurant


Let’s simplify even more. You have seen this example a lot of time as a meme…
6

Imagine a web server is like the front-of-house staff in a restaurant:

● The waiter (web server) takes your order (browser request),


● Passes it to the kitchen (backend),
● Bring the meal (web page) back to your table (browser).

Sometimes, it just grabs pre-made sandwiches (static files), and other times it has to
wait for the chef to cook something fresh (dynamic content). Either way, it makes sure
you get what you ordered.

🧩 Summary: Why Web Servers Matter


Without web servers, the internet as we know it wouldn’t exist. They:

● Keep websites available 24/7,


● Handle millions of requests,
● Serve content securely and efficiently.

And the best part? You can set one up yourself in less than 10 minutes with just a few
commands. Whether it’s for a personal blog or a global e-commerce site, web servers
are the backbone of it all.

1.2 Client-Server Model Explained


Okay, so we now know that a web server sends stuff to your browser when you ask for
it. But how does this whole relationship actually work?

Let’s introduce the internet’s power couple: the Client and the Server.

󰠁 + 🖥 = Client-Server Model
7

The Client-Server Model is the basic way the web works. It’s like a two-person
conversation:

● The client is you—well, technically, it’s your browser (Chrome, Firefox, Safari,
etc.).
● The server is the web server that hosts the website or web application.

The client says, “Hey server, I need this thing.”

The server replies, “Sure, here you go!” (or sometimes, “Sorry, I can’t find that.”)

This back-and-forth is what powers every website you’ve ever visited.

🔄 The Request-Response Lifecycle


Let’s walk through what actually happens when you visit a website, like
www.codelivly.com.

1. You type in the URL in your browser and hit Enter.

2. Your browser looks up the domain name through DNS (Domain Name System)
and finds the server’s IP address.

3. Your browser sends a request to the web server—usually an HTTP request that
says:
“GET me the homepage!”

4. The web server receives the request and checks its files.

5. It finds index.html, bundles it up, and sends it back as a response.

6. Your browser unpacks the response and shows you the tasty cake website.

This whole thing takes less than a second. (Unless you’re on hotel Wi-Fi... then, good
luck.)
8

🧠 It’s All About Roles


To be clear—client and server aren’t specific pieces of software. They’re roles in a
conversation.

Sometimes, the same machine can act as both.

● When you open localhost on your laptop to test a web app, your machine is
both client and server.
● In multiplayer gaming, your computer might act as the server for others.

But in web terms, we usually talk about a client as the one asking, and the server as the
one responding.

🧊 Stateless vs. Stateful Protocols


Here’s a fun fact: HTTP—the main protocol web servers use—is stateless.

That means every time you send a request, it’s like a fresh conversation. The server has
no memory of what you did a minute ago unless you give it tools to remember.

Think of it like a vending machine:

● You press the button, it gives you a snack.


● But it doesn’t remember your last purchase.
● If you want it to remember you? You’ll need to attach a sticky note (that’s kind of
what a cookie does).

To create “memory” between client and server, developers use:

● Cookies: Small text files stored in the browser


● Sessions: Temporary data on the server side
● Tokens: Like keys passed between the client and server to verify identity

🌍 Examples in Real Life


Here are a few relatable client-server interactions you’ve likely experienced:
9

Action Client Server

Watching a YouTube Your browser YouTube’s server streams the video


video

Logging into Gmail Your phone or Google’s mail server handles your login
PC

Buying shoes online Your device The store’s server shows the product and
processes payment

It’s happening around you all day, every day—even when you don’t realize it.

🧩 Summary: Why This Matters


The client-server model is the backbone of how the internet works. It’s the reason why
you can:

● Browse websites
● Watch videos
● Play games online
● Send messages to friends

And the best part? It’s simple at its core—one side asks, the other side responds.

Once you understand this model, everything else in web development starts to click into
place.
10

1.3 Evolution of Web Servers


The internet today is lightning-fast, packed with video, AI, real-time chats, and beautifully
designed websites. But it didn’t start out this way. In fact, the early web was a lot like a
library in a small town—quiet, simple, and mostly text.

To understand how far web servers have come, let’s take a little time-travel trip, starting
from the '90s all the way to modern-day cloud computing.

🕰 The Early Days – CERN and the First Web Server


Let’s rewind to 1990.

At a research lab in Switzerland called CERN, a brilliant guy named Tim Berners-Lee
had an idea: what if researchers could easily share documents using something called
hypertext? That idea led to the invention of the World Wide Web.

And to make it work, he created the first-ever web server on a NeXT computer (yes,
that’s the company Steve Jobs started after leaving Apple). The software was called
simply:

“httpd” (short for Hypertext Transfer Protocol Daemon).

It could handle basic HTTP requests and send back static web pages (just text and
hyperlinks, no images yet!). The very first website? It explained what the web was and
how to use it. Simple. Revolutionary.

🌐 The Rise of Apache – The First Real Powerhouse


As the web started to grow in the mid-90s, there was a need for more powerful and
flexible web servers.

Enter: Apache HTTP Server, launched in 1995.

Apache quickly became the go-to web server for developers and businesses. Why?

● It was open-source (free to use and modify),


● Had a modular architecture (you could plug in features),
11

● Ran on multiple platforms (Linux, Windows, etc.),


● And had a huge community behind it.

For years, Apache powered the majority of websites on the internet. If you made a
personal blog or small business site in the 2000s, chances are it was running on
Apache.

🚀 Enter Nginx – Built for Speed and Scalability


By the mid-2000s, the internet was exploding—millions of users, richer content, more
traffic. Apache was still great, but it started showing its age under heavy loads.

Then came Nginx (pronounced “engine-x”), launched in 2004 by Igor Sysoev.

Nginx was designed from the ground up to handle:

● High concurrency (lots of users at once),


● Reverse proxying (passing requests to backend apps),
● Load balancing (splitting traffic across multiple servers),
● And it was blazingly fast.

Instead of creating a new thread for each user (like Apache), Nginx used an
event-driven model, meaning it could serve thousands of users with just a few
resources.

Companies like Netflix, Airbnb, and Dropbox started using it. It became the go-to
solution for high-performance websites.

🪟 Microsoft IIS – The Windows World


While Apache and Nginx were dominating the open-source world, Microsoft had its own
player: IIS (Internet Information Services).

IIS was deeply integrated with Windows Server and worked seamlessly with
technologies like:

● ASP.NET
● Microsoft SQL Server
12

● Active Directory

If a company was already running Windows infrastructure, IIS was a natural choice. It’s
still widely used in enterprise environments, especially for internal apps and
Microsoft-based stacks.

☁ The Modern Era – Cloud, Containers, and Serverless

Fast forward to today. Web servers are still critical, but now they live in more dynamic,
flexible environments. Here’s what’s new:

🌩 Cloud-Native Servers
● Hosting has moved to platforms like AWS, Azure, and Google Cloud.
● You can spin up a full web server in seconds using tools like EC2, Lightsail, or
App Engine.

🐳 Containers and Microservices


● Instead of running everything on one big server, we now split apps into
containers (hello, Docker).
● Each service can be deployed independently, scaled automatically, and run
anywhere.

⚙ Serverless Architectures
● With services like AWS Lambda, you don’t even need to manage a web server
anymore.
● You just write a function, upload it, and it runs whenever someone makes a
request.
● No patching, no scaling, no infrastructure.

🌍 Edge Computing and CDN-Based Hosting


● CDNs like Cloudflare, Netlify, and Vercel are now delivering content from servers
closer to the user—cutting latency and improving speed.
13

📊 Timeline Recap: Evolution at a Glance


Year Milestone Web Server

1990 First website at CERN httpd (Tim Berners-Lee)

1995 Open-source boom begins Apache HTTP Server

2004 High-performance era starts Nginx

1996–No Microsoft-backed alternative IIS


w

2010s–No Cloud-native, serverless, and AWS, Docker, Kubernetes, Vercel,


w containerized etc.

🎯 Final Thoughts
Web servers have evolved from simple text-file fetchers to powerful, cloud-based
engines that drive modern applications.

And while the names and tools have changed, the goal remains the same: get content
from point A (the server) to point B (the user)—as fast, safely, and reliably as possible.
14

1.4 Role in Web Architecture


By now, we know a web server delivers content to browsers. Cool. But in the big picture
of a real-world web application, that’s just one piece of the puzzle.

Modern websites and apps are built like well-oiled machines, with many moving parts
working together. And the web server? It’s smack in the middle of it all—the coordinator,
the gatekeeper, and the messenger.

Let’s break it down.

Web architecture is how all the parts of a web app are structured and connected—like
the blueprint of a house, but for websites.

Imagine a simple site:

● A user visits the page


● Some data is fetched (like recent blog posts)
● The result is shown to the user

Behind that simple interaction is a whole chain of systems working in sync:

● The browser (client)


● The web server
● Backend applications
● Databases
● APIs
● CDNs
● Firewalls
● Caches

Let’s zoom in on the web server’s role.

🚪 1. The Web Server is the Front Door


When a visitor comes to your website, the web server is the first one to answer the
door.
15

It:

● Accepts the incoming request (like “GET /blog”),


● Figures out where to send it (serve a static file or call the backend),
● And returns the appropriate response (HTML, data, error page, etc.).

In tech terms, it routes, proxies, or serves content.

🧱 2. Static vs. Dynamic Content Delivery


Web servers handle both static content and dynamic content—but the process is
different.

Type Example Who Handles It

Static Images, CSS, JS, HTML Served directly from disk by the web server

Dynami User dashboard, blog Forwarded to backend apps (like Node.js,


c post, login form Django, PHP) to generate responses

So, the web server either acts like a waiter bringing a dish from the kitchen, or like a
messenger relaying your order to the chef (backend app).

🧠 3. Talking to the Backend (App Servers)


When things get dynamic, the web server often passes requests to an application
server. For example:

● Apache may use mod_php to run PHP scripts


● Nginx might forward requests to Gunicorn (Python), Node.js, or PHP-FPM

This is called a reverse proxy setup:

● Nginx → App Server → Database


● Apache → PHP → MySQL
16

The web server acts as the traffic controller, directing requests to the right backend
system.

🗂 4. Connecting to Databases
Web servers themselves don’t usually talk directly to databases like MySQL or
PostgreSQL. Instead, they pass requests to backend apps, which then talk to the
database, fetch the data, and send it back.

But the web server still plays a vital role in this dance by:

● Managing sessions or authentication cookies


● Caching responses to reduce repeated DB hits
● Enforcing access rules (e.g., block /admin for guests)

🚦 5. Load Balancing and High Availability


In big setups, web servers can also act as load balancers—splitting incoming traffic
across multiple app servers so no single server gets overwhelmed.

Example:

● You have 3 backend servers


● Nginx sits in front and evenly distributes requests
● If one server crashes, it reroutes traffic to the other two

This helps with:

● Scalability (handle more users)


● Reliability (no single point of failure)

🌎 6. Working with CDNs and Caching Layers


A web server often works side-by-side with a CDN (Content Delivery Network). CDNs
serve content (like images or videos) from edge servers that are physically closer to
users.

● Web server handles the app logic


17

● CDN handles the heavy lifting of media files and static content

This offloads work from your main server and speeds things up for global visitors.

🔐 7. Handling Security and Traffic Rules


The web server is also where a lot of security enforcement happens, such as:

● Blocking bad bots or suspicious IPs


● Enforcing HTTPS with SSL certificates
● Applying rate limits (stop brute force attacks)
● Redirecting or rewriting URLs (SEO, clean URLs)

In short: it’s the first line of defense before a request even touches your app.

🧩 Summary: Web Server’s Place in the Stack


Let’s visualize a basic stack:

And often, it’s even more complex with:

● CDNs
● Firewalls
● Caching layers
● Microservices
● APIs

Through all of this, the web server is always in the middle—coordinating, delivering,
securing, and optimizing.
18

2. Types of Web Servers


Not all web servers are created equal. They may all do the same basic job—serve
content to users—but the way they do it, the performance, the features, and the use
cases can vary a lot.

Choosing the right web server is kind of like choosing the right tool for a job.

● If you’re building a simple blog, you might want something lightweight and easy
to set up.
● If you’re hosting a massive streaming platform or a banking app, you’ll need
something fast, secure, and scalable.

Over the years, several types of web servers have become popular in the tech world,
each with its strengths, quirks, and best-fit scenarios. Some are open-source and
community-powered, while others are proprietary and built into specific ecosystems
(like Windows).

In this chapter, we’ll explore:

● The difference between open-source vs. proprietary web servers,


● How different web servers like Apache, Nginx, and IIS stack up,
● And even check out some newer, lightweight options like Caddy and LiteSpeed
that are gaining traction.

By the end of this chapter, you'll have a solid understanding of what each server brings
to the table—and which one might be the best fit for your project or organization.
19

2.1 Open-Source vs. Proprietary Solutions


When you're choosing a web server, one of the first big decisions you'll face is:

Do I go open-source or proprietary?

This isn’t just a licensing decision—it can affect how much control you have, how much
you pay, how you configure and scale, and even how fast your team can troubleshoot
problems.

Let’s break it down.

🟢 Open-Source Web Servers


Open-source software is made available to the public under licenses that allow anyone
to view, modify, and distribute the code. These servers are developed and maintained by
large communities of developers (or sometimes companies), and they’re free to use.

✅ Key Features of Open-Source Web Servers


● Free (as in freedom and price): No licensing costs. You can use them for
personal projects or large-scale commercial applications.
● Customizable: You can tweak configuration files, build your own modules, or
even modify the source code itself.
● Community-driven support: You get access to forums, GitHub repos, tutorials,
Stack Overflow answers, and detailed documentation.
● Wide ecosystem: Tons of plugins, modules, and integrations built by the
community.

🔧 Popular Open-Source Web Servers


● Apache HTTP Server – One of the oldest and most battle-tested servers out
there.
● Nginx – Lightweight, high-performance, and super popular for reverse proxying
and load balancing.
● Caddy – Automatically handles HTTPS and SSL certificates with zero config.
Great for small, modern apps.
This is a draft of our New eBook
On Web Server

will be published by Codelivly


Written By Rocky

You might also like