A lightweight, high-performance HTTP web server implemented in C++98, inspired by NGINX configuration syntax and designed for modern web applications.
ServIO is a custom HTTP/1.1 web server that provides essential web server functionality including static file serving, CGI support, file uploads, redirections, and virtual host management. The server uses a configuration system similar to NGINX, making it familiar and easy to configure.
- HTTP/1.1 Protocol Support - Full implementation of HTTP/1.1 with persistent connections
- Virtual Hosts - Multiple server blocks with different ports and server names
- Static File Serving - Efficient serving of static content with MIME type detection
- CGI Support - Execute server-side scripts (Python, PHP, etc.)
- File Upload - Handle file uploads with configurable storage locations
- URL Redirections - Support for HTTP redirects (301, 302, etc.)
- Directory Indexing - Automatic directory listing when enabled
- Error Pages - Customizable error pages for different HTTP status codes
- Request Size Limits - Configurable maximum request body size
- Method Restrictions - Control allowed HTTP methods per location
- Polling I/O - Non-blocking I/O using poll() for high concurrency
- Signal Handling - Proper signal management for graceful operation
The server is built with a modular architecture:
- Core (
src/core/
) - Main server logic, configuration parsing, and AST - HTTP (
src/http/
) - HTTP protocol implementation, request/response handling - Utility (
src/utility/
) - Socket management, logging, and helper functions
- Configuration Parser - Lexer and parser for NGINX-like configuration syntax
- Socket Manager - Non-blocking socket operations with poll()
- Client Manager - Connection handling and lifecycle management
- Request Processor - HTTP request parsing and validation
- Response Generator - HTTP response construction and delivery
- CGI Handler - External script execution and communication
- Compiler: C++ compiler with C++98 standard support
- Build System: GNU Make
- Platform: Unix-like systems (Linux, macOS)
- Clone the repository:
git clone <repository-url>
cd servIO
- Build the server:
make
- Clean build artifacts:
make clean # Remove object files
make fclean # Remove all build artifacts
make re # Clean rebuild
ServIO uses a configuration file syntax similar to NGINX. The default configuration is located at conf/servio.conf
.
http {
client_max_body_size 30m;
server {
listen 80;
server_name example.com;
location / {
root html;
index index.html;
}
location /cgi {
cgi_assign ".py";
}
location /upload {
upload_store /tmp;
}
}
}
client_max_body_size
- Maximum size of client request bodyroot
- Document root directoryallowed_methods
- Allowed HTTP methods (GET, POST, DELETE)autoindex
- Enable/disable directory listingindex
- Default index fileserror_page
- Custom error page mapping
listen
- Port to listen onserver_name
- Virtual host server namereturn
- HTTP redirect response
cgi_assign
- File extensions for CGI executionupload_store
- Directory for file uploadsreturn
- Location-specific redirects
The complete BNF grammar for the configuration file is documented in conf/grammar.md
.
- Start the server with default configuration:
./servio
- Use custom configuration:
./servio -c /path/to/config.conf
- Check configuration syntax:
./servio -t
The server will start listening on the configured ports and serve content according to the configuration directives.
http {
server {
listen 8080;
location / {
root /var/www/html;
autoindex on;
}
}
}
http {
server {
listen 80;
location / {
root html;
}
location /cgi-bin {
cgi_assign ".py" ".php";
}
}
}
http {
client_max_body_size 100m;
server {
listen 80;
location /upload {
allowed_methods POST;
upload_store /var/uploads;
}
}
}
servIO/
├── src/
│ ├── core/ # Core server functionality
│ ├── http/ # HTTP protocol implementation
│ ├── utility/ # Utility functions and helpers
│ └── sio_main.cpp # Main entry point
├── conf/
│ ├── servio.conf # Default configuration
│ └── grammar.md # Configuration grammar documentation
├── html/ # Default web content
├── logs/ # Log files
├── Makefile # Build configuration
└── .gitignore # Git ignore rules
- C++98 standard compliance
- RAII principles for resource management
- Error handling with exceptions where appropriate
- Memory leak prevention with proper cleanup
The server is built with debugging symbols (-ggdb
) and includes AddressSanitizer support for memory error detection.
The configuration includes test locations for validating various server features:
- Method restrictions (
/tests/allow
) - Body size limits (
/tests/max_size
) - CGI execution (
/cgi
) - File uploads (
/upload
) - Redirections (
/redirect
)
- Follow the existing code style and C++98 standards
- Test your changes with various configuration scenarios
- Ensure memory safety and proper error handling
- Update documentation for new features
This project is provided as-is for educational and development purposes.