This is a lightweight HTTP web server built in C from the ground up. If you want to learn how web servers work under the hood this is the resource that you're looking for!
Currently this server support multiple features such as,
- 📁 Serve Static Files — Effortlessly serve HTML, CSS, JavaScript, images, and more
- 🎯 MIME Type Support — Automatic content-type detection for proper file rendering
- ⚙️ Custom Port Configuration — Launch your server on any port you prefer
- 💻 Lightweight — Minimal dependencies, pure C implementation
- 🔧 Easy to Use — Simple command-line interface with intuitive options
- GCC compiler
- Linux/Unix environment (uses POSIX.1)
gcc -o web_server main.c./web_server -p 3000Then open your browser and visit:
http://localhost:3000
web_server/
├── main.c # Core server implementation
├── public/ # Static files directory
│ ├── index.html # Home page
│ ├── style.css # Styling
│ └── script.js # Frontend logic
└── utils/
└── filehelper.c # Utility functions for file handling & MIME types
- Server Setup — Binds to a TCP socket and listens for incoming connections
- Request Parsing — Reads HTTP requests from clients
- File Serving — Locates requested files in the
public/directory - MIME Detection — Automatically detects file type and sets correct content-type headers
- Response Sending — Sends HTTP responses with proper headers and file content
The server intelligently detects file types:
.html,.htm→text/html.css→text/css.js→application/javascript.png,.jpg,.gif→ Image types- And many more...
Start your server on any port with the -p flag:
./web_server -p 5000- Socket Programming — TCP/IP communication
- HTTP Protocol — Request/response handling
- File I/O — Reading and serving file content
- String Manipulation — Parsing HTTP requests and building responses
- Memory Management — Efficient allocation and cleanup
I'll add these features later but you are feel free to extend this project! Some ideas such as:
- Add support for multiple concurrent clients (threading)
- Implement POST request handling
- Add basic routing
- Support for CGI scripts
- Performance optimizations
This project is provided as-is for educational purposes.
⭐ Made with passion for learning low-level networking!