A high-performance web server written in pure C, inspired by Nginx architecture.
┌─────────────┐ │ Master │ │ Process │ └──────┬──────┘ │ ├─────────────┬─────────────┬─────────────┐ │ │ │ │ ┌───▼───┐ ┌───▼───┐ ┌───▼───┐ ┌───▼───┐ │Worker 1│ │Worker 2│ │Worker 3│ │Worker N│ └───┬───┘ └───┬───┘ └───┬───┘ └───┬───┘ │ │ │ │ ┌───▼─────────────▼─────────────▼─────────────▼───┐ │ Event Loop (epoll) │ └──────────────────────────────────────────────────┘
# Build the project
make
# Clean build artifacts
make clean
# Rebuild from scratch
make rebuild
# Build with debug symbols
make debug
# Start server with default settings (port 8080, 4 workers)
./bin/nginx
# Start server on custom port
./bin/nginx -p 9000
# Start with specific number of workers
./bin/nginx -w 8
# Run as daemon
./bin/nginx -d
# Test configuration
./bin/nginx -t
# Show help
./bin/nginx -h
# Show version
./bin/nginx -v
| Option | Description | Default |
|---|---|---|
-p, --port PORT | Set listen port | 8080 |
-w, --workers NUM | Number of worker processes | 4 |
-d, --daemon | Run as daemon | false |
-t, --test | Test configuration | - |
-v, --version | Show version | - |
-h, --help | Show help | - |
nginx-c/ ├── src/ │ ├── nginx.c # Main entry point │ ├── config.h/c # Configuration management │ ├── master.c/h # Master process management │ ├── worker.c/h # Worker process implementation │ ├── event.c/h # Event loop (epoll wrapper) │ ├── http.c/h # HTTP protocol parsing │ └── log.c/h # Logging system ├── html/ # Static files directory │ └── index.html # Default welcome page ├── logs/ # Log files directory ├── obj/ # Build objects ├── bin/ # Build output └── Makefile # Build configuration
The server uses a simple configuration system:
typedef struct {
int port; // Listen port
int worker_processes; // Number of workers
int worker_connections; // Connections per worker
char access_log[MAX_PATH_LEN];
char error_log[MAX_PATH_LEN];
char pid_file[MAX_PATH_LEN];
int daemon;
server_config_t server;
} global_config_t;
Default settings:
./htmlindex.htmlStart the server and access it in a browser:
./bin/nginx
# Then visit: http://localhost:8080
Test with curl:
curl http://localhost:8080 curl -I http://localhost:8080
Logs are written to:
logs/access.log - HTTP access logslogs/error.log - Error messagesLog format:
[2025-02-15 10:30:45.123] [INFO] Server listening on port 8080 127.0.0.1 - - [15/Feb/2025:10:30:50 +0000] "GET /index.html HTTP/1.1" 200 1234
The server is designed for high performance:
This is an educational project demonstrating web server implementation.
Contributions are welcome! Please feel free to submit issues and pull requests.
Created as a demonstration of web server implementation in pure C.