This is a simple HTTP server implementation in C that supports static file serving and configurable routes (it was written in order to understand how web-server works). The server uses a hash map to store routes and supports both string-based and regex-based mappings
- Serves static files
- Configurable routing through a configuration file
- Supports both exact and regex-based URL mappings
Ensure you have the following dependencies installed:
- GCC (or Clang)
- GNU Make
To compile the server, run:
make
This will generate an executable named server
To start the server, use:
./server
By default, the server reads the configuration from server.conf. You can specify a custom configuration file:
./server /path/to/config.conf
The server uses a structured configuration file (server.conf) to define routing and server settings
http {
port: 14880;
web_root: ./www/;
route {
web_root: ./www/subfolder/;
mapping: /200;
file_path: 200.html;
}
route {
mapping: /;
file_path: index.html;
}
route {
mapping[regex]: /help*;
file_path: index.html;
}
}
port: Specifies the port the server will listen onweb_root: The root directory for serving filesroute: Defines individual routes with the following properties:mapping: URL path to matchmapping[regex]: Specifies a regex-based routefile_path: The file that will be served for this routeweb_root(optional): Overrides the globalweb_rootfor this route