A simple static file web server built from scratch in C++ using low-level socket programming.
This project demonstrates how web servers work under the hood by manually handling TCP connections and parsing HTTP requests.
- β
Serves static files from the
public/
directory - β Parses raw HTTP GET requests
- β Dynamically detects and serves correct MIME types
- β
Custom 404 page support (
public/404.html
) - β
Handles multiple clients using
fork()
- β Written with only standard C/C++ libraries (no external dependencies)
http-server-from-scratch/
βββ server.cpp # Core server logic
βββ public/ # Static files served by the server
β βββ index.html
β βββ style.css
β βββ 404.html
βββ Makefile # Build instructions
βββ README.md # This file
- Linux (e.g., Ubuntu)
- g++ compiler
make
./server
curl http://localhost:8080/
- Server binds to port 8080
- Listens for TCP connections
- Forks a child process to handle each incoming client
- Reads the HTTP request line
- Extracts the file path and serves it if available
- Sets appropriate Content-Type based on file extension
- Returns a 404 page if the file isnβt found
- Support HTTP POST and other methods
- Add threading instead of fork() for concurrency
- Log requests and status codes
- Add command-line options for port or root directory
- HTTP/1.1 features (Keep-Alive, headers)
Built as a learning project to understand low-level networking and HTTP. Feel free to fork, modify, or suggest improvements!