An HTTP/1.1 web server written in C++98, built from scratch as part of the 42 School curriculum.
Webserv is an HTTP/1.1 web server that handles client requests over TCP. It uses an event-driven architecture for I/O multiplexing and covers network programming, socket management, HTTP parsing, and concurrent connection handling.
- Core HTTP/1.1 request and response handling
- GET, POST, and DELETE methods
- Event-driven I/O multiplexing using epoll (Linux) and kqueue (macOS)
- NGINX-like configuration file format
- Virtual hosting with multiple server blocks
- CGI script execution (.php, .py, .pl)
- Chunked transfer encoding for request bodies
- Keep-alive connections
- Configurable error pages (404, 500, etc.)
- Optional directory listing (autoindex)
- HTTP redirects (301, 302, etc.)
- File uploads with configurable body size limits
- Logging for debugging and monitoring
The server is organized around three core components: an event poller for I/O multiplexing, a configuration parser for NGINX-style config files, and a logger for runtime output. The event poller uses epoll on Linux and kqueue on macOS. Incoming connections are managed by a connection handler that parses HTTP requests and builds responses through dedicated request and response modules.
- C++ compiler with C++98 support (g++, clang++)
- Make
- Supported platforms: Linux (epoll), macOS (kqueue)
git clone https://github.com/Mouad-kimdil/webserver.git
cd webserver
makeAdditional make targets:
make clean # Remove object files
make fclean # Remove object files and binary
make re # Rebuild from scratch./webserv
./webserv configs/your_config.confManual checks with curl:
curl http://localhost:8081/
curl -X POST -d "data=test" http://localhost:8081/upload/You can also open http://localhost:8081 in a web browser.
The official 42 School test binaries (tester and cgi_tester) are not included in this repository because of their size. Obtain them from the webserv subject resources or your campus, then place them in the testers/ directory:
mkdir -p testers
cp /path/to/tester testers/tester
cp /path/to/cgi_tester testers/cgi_tester
chmod +x testers/tester testers/cgi_testerRun the server first, then execute the testers from another terminal:
./testers/tester http://localhost:8081
./testers/cgi_testerFor setup requirements and expected directory layout, see the 42 webserv tester documentation.
The server uses an NGINX-like configuration format. Configuration files are located in the configs/ directory.
error_log error.log;
http {
server {
listen 8081;
server_name localhost www.localhost;
root /var/www/html;
index index.html;
client_max_body_size 10M;
error_page 404 /404.html;
error_page 500 /500.html;
location / {
allowed_methods GET POST DELETE;
autoindex off;
}
location /upload/ {
allowed_methods GET POST DELETE;
client_max_body_size 100M;
}
location /cgi-bin/ {
root /var/www/cgi-bin;
cgi_extension .php /usr/bin/php;
cgi_extension .py /usr/bin/python3;
allowed_methods GET POST;
}
location /old-page {
return 301 /new-page;
}
}
}| Directive | Description |
|---|---|
listen |
Port and optional IP address to listen on |
server_name |
Virtual host names |
root |
Document root directory |
index |
Default index file |
error_page |
Custom error page paths |
client_max_body_size |
Maximum allowed request body size |
allowed_methods |
Permitted HTTP methods |
autoindex |
Enable/disable directory listing |
cgi_extension |
CGI script extensions and interpreters |
return |
HTTP redirects |
webserver/
├── configs/ # Configuration files
│ ├── default.conf
│ └── test_server.conf
├── includes/ # Header files
│ ├── Parse/
│ ├── Request/
│ ├── Response/
│ ├── Server/
│ └── Utils/
├── Parse/ # Configuration parsing
├── Request/ # HTTP request handling
├── Response/ # HTTP response building
├── Server/ # Core server implementation
├── Utils/ # Utility functions
├── var/www/ # Default web content directory
├── resources/ # Documentation and references
├── Subject/ # Project subject and requirements
├── testers/ # 42 test binaries (local only, not tracked)
├── webserv.cpp # Main entry point
├── Makefile
└── README.md
- Mouad Kimdil
- Es-salhi Mohammed Amine
- Hamza El Asli