Quick Start
The httpz static file server is available asbin/httpz_server.exe and can be run with sensible defaults:
Command-Line Options
The server accepts two optional flags for configuration:Port Configuration
Specify the TCP port to listen on using the-p flag:
Port number to listen on for HTTP connections. Must be a valid TCP port (1-65535).
Directory Configuration
Specify the directory to serve using the-d flag:
Directory path to serve files from. Can be absolute or relative to the current working directory.
Usage Examples
Server Output
When the server starts, it displays configuration information:The server logs the directory being served and the URL to access it, along with supported HTTP features.
Implementation Details
The command-line interface is built using OCaml’sCommand library:
Server Limits
The server has the following built-in limits for security and performance:Maximum number of concurrent client connections
TCP listen backlog for pending connections
Size of the response header buffer in bytes (64KB)
Size of the request buffer in bytes (32KB, from
Httpz.buffer_size)HTTP Parser Limits
The server uses default httpz parser limits:- Maximum header count
- Maximum header size
- Maximum request line length
- Content-length overflow detection
Parser limits help prevent denial-of-service attacks and ensure efficient memory usage.
Connection Management
The server creates a TCP listener with these characteristics:Error Handling
Connection errors are caught and logged with the client address:Network Configuration
Listening Address
The server binds to all interfaces on the specified port:localhost/127.0.0.1- Local network interfaces
- External interfaces (if firewall permits)
Environment Requirements
OxCaml Compiler
Requires the OxCaml compiler from oxcaml.org for unboxed type support
OCaml Dependencies
The following OCaml libraries must be installed:
core- Base functionalityasync- Asynchronous I/Ocore_unix- Unix system calls
Production Deployment
For production use, consider:Reverse Proxy
Reverse Proxy
Run httpz behind nginx or another reverse proxy for:
- TLS/SSL termination
- Load balancing
- Additional caching layers
- Access logging
Process Management
Process Management
Use a process supervisor like:
- systemd (Linux)
- supervisord
- Docker containers
File Permissions
File Permissions
Ensure the server process has:
- Read access to served directories
- No write access (defense in depth)
- Minimal privileges (non-root user)
Monitoring
Monitoring
Consider adding:
- Connection count metrics
- Request latency tracking
- Error rate monitoring
- Health check endpoints
Next Steps
Server Overview
Learn about server features and capabilities
Performance
Understand httpz performance characteristics