A lightweight, HTTP/1.1 compliant web server built in C++17 for educational purposes as part of the 42 school curriculum.
- HTTP/1.1 Protocol: RFC 9110/9112 compliant
- HTTP Methods: GET, POST, DELETE support
- Static File Serving: HTML, CSS, JS, images, etc.
- Directory Listings: Automatic index generation
- File Uploads: Multipart form data handling
- Custom Error Pages: With fallback defaults
- Configuration System: Nginx-style config parsing
- Virtual Hosts: Multiple server support
- Location Blocks: Routing with method restrictions
- Chunked Transfer: Request body support
- Connection Management: Keep-alive and timeout handling
- Event-Driven I/O: Epoll-based architecture
- Security: Path traversal protection
- Logging: Basic request/error logging
- CGI Support: Dynamic script execution
webserv/
├── includes/ # Header files
│ └── *.hpp
├── srcs/ # Source files
│ ├── Config/ # Configuration system
│ ├── main.cpp # Server entry point
│ └── *.cpp
├── docs/ # Static web content
│ └── fusion_web/ # Demo website
├── tests/ # Unit tests
└── Makefile # Build systemDemo website structure
docs/fusion_web/
├── index.html # Main landing page
├── style.css # Shared stylesheet
├── tours/ # Static content example
├── uploads/ # File upload destination
├── cgi-bin/ # CGI scripts
│ ├── time.py # Python CGI example
│ └── hello.py # Simple CGI demo
└── error_pages/ # Custom error pages
└── 404.htmlPrerequisites
- C++17 compatible compiler.
- Make build system.
- Linux/Unix environment.
Building
# Clone the repository
git clone <repository-url>
cd webserv
# Build the server
make
# Build with tests (optional)
make test-unitRunning
# Start server with default configuration
./webserv
# Start server with config file
./webserv [path/to-config-file.conf]
# View logs
tail -f logs/webserv.log
# Test manually
curl http://localhost:8002/
curl -X POST -F "[email protected]" http://localhost:8002/uploads/Basic server block:
server {
listen 8002;
server_name localhost;
root docs/fusion_web/;
index index.html;
error_page 404 error_pages/404.html;
location / {
allow_methods GET POST DELETE;
}
location /uploads {
allow_methods GET POST;
autoindex on;
}
location /cgi-bin {
allow_methods GET POST;
cgi_path /usr/bin/python3 /bin/bash;
cgi_ext .py .sh;
}
}Configuration directives Server directives:
listen: Port number to bind toserver_name: Virtual host nameshost: IP addressroot: Document root directoryindex: Default file to serveerror_page: Custom error page mappings
Location directives:
allow_methods: Permitted HTTP methodsautoindex: Enable/disable directory listingsreturn: HTTP redirect configurationcgi_path: CGI interpreter pathscgi_ext: CGI file extensions
Developed by