WebServ is built with modern C++20 and requires a recent compiler and CMake for building.
# Clone the repository git clone https://github.com/WHaffmans/webserv.git cd webserv # Build the project make # Or build with specific configuration make build_type=release make build_type=debug make build_type=asan
debug: Debug symbols, no optimizationrelease: Optimized build for productionasan: Address sanitizer for memory debugging
WebServ uses nginx-style configuration files for maximum flexibility and familiarity.
# webserv.conf
server {
listen 8080;
server_name localhost;
root ./www;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
# Advanced webserv.conf
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
# Error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# Static files with caching
location /static/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# API endpoints
location /api/ {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# Directory listing
location /files/ {
autoindex on;
autoindex_exact_size off;
}
}
# HTTPS server
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
root /var/www/ssl;
index index.html;
}
# Run with default configuration ./build/webserv # Run with custom configuration file ./build/webserv config/webserv.conf # Run with make target (rebuilds if needed) make run
Usage: webserv [config_file] Arguments: config_file Path to configuration file (default: webserv.conf) Examples: ./webserv # Use default config ./webserv /etc/webserv.conf # Use specific config ./webserv --help # Show help message
# Test with curl curl http://localhost:8080/ # Test with specific headers curl -H "Host: example.com" http://localhost:8080/ # Test POST request curl -X POST -d "test=data" http://localhost:8080/api/test
# Apache Bench ab -n 1000 -c 10 http://localhost:8080/ # wrk load testing wrk -t12 -c400 -d30s http://localhost:8080/ # siege testing siege -c 50 -t 30s http://localhost:8080/
# Build and run tests make test # Run specific test suite cd build && ctest -V # Run with Google Test directly ./build/webserv_tests
# Check what's using the port sudo netstat -tlnp | grep :8080 sudo lsof -i :8080 # Kill process using the port sudo kill -9 <PID>
# For ports below 1024, run as root sudo ./build/webserv # Or use a port above 1024 # Edit config: listen 8080;
# Check configuration syntax ./build/webserv -t config/webserv.conf # Debug mode for detailed logging ./build/webserv_debug config/webserv.conf
WebServ logs are written to both console and log files:
# Default log locations ./logs/access.log # Access logs ./logs/error.log # Error logs ./logs/debug.log # Debug logs (debug build only) # Tail logs in real-time tail -f logs/access.log tail -f logs/error.log
For development and troubleshooting, use the debug build:
# Build debug version make build_type=debug # Run with debug logging ./build/webserv_debug # Use with GDB for debugging gdb ./build/webserv_debug (gdb) run config/webserv.conf
make build_type=asan) to catch memory errors during development.
Need more help? Check out the Configuration Guide or API Reference.