Skip to content
/ bws Public

BWS (Blazing Web Server) is a production-ready web server and reverse proxy that prioritizes memory safety and performance. Built on Cloudflare's Pingora framework with Rust's ownership model, BWS eliminates entire classes of security vulnerabilities while delivering enterprise-grade performance.

License

Notifications You must be signed in to change notification settings

benliao/bws

Repository files navigation

BWS Web Server

CI Security Crates.io License: MIT

High-performance, multi-site web server built with Rust and Cloudflare's Pingora framework.

Features

  • Multi-Site Hosting - Multiple websites with individual configurations
  • Automatic SSL/TLS - Let's Encrypt integration with auto-renewal
  • Reverse Proxy & Load Balancing - Multiple algorithms and WebSocket support
  • Hot Reload - Zero-downtime configuration updates
  • Memory Safety - Rust eliminates buffer overflows and memory leaks
  • Enterprise Ready - Production-grade reliability and management

Quick Start

Instant Directory Server

# Serve current directory on port 80
bws .

# Serve specific directory on custom port
bws /path/to/website --port 8080

Installation

# From crates.io
cargo install bws-web-server

# From Docker
docker run -d -p 8080:8080 ghcr.io/benliao/bws:latest

# From source
git clone https://github.com/benliao/bws.git && cd bws
cargo build --release

Configuration-Based Setup

Create config.toml for production:

[server]
name = "BWS Server"

[[sites]]
name = "main"
hostname = "localhost"
port = 8080
static_dir = "static"
default = true

[sites.ssl]
enabled = false

# Multiple sites on same port (virtual hosting)
[[sites]]
name = "blog"
hostname = "blog.localhost"
port = 8080
static_dir = "static-blog"

# Reverse proxy setup
[[sites]]
name = "api"
hostname = "api.localhost"
port = 8080

[sites.proxy]
enabled = true

[[sites.proxy.upstreams]]
name = "backend"
url = "http://127.0.0.1:3001"

[[sites.proxy.routes]]
path = "/api/"
upstream = "backend"

# HTTPS with automatic certificates
[[sites]]
name = "secure"
hostname = "example.com"
port = 443

[sites.ssl]
enabled = true
auto_cert = true

[sites.ssl.acme]
enabled = true
email = "[email protected]"

Run

# Quick start - serve directory
bws static --port 8080

# With configuration file
bws -c config.toml

# Validate configuration first
bws -c config.toml --dry-run

Architecture

BWS uses a modular, enterprise-grade architecture:

src/
├── core/              # Foundation: types, error handling
├── config/            # Configuration management
├── handlers/          # Request processing (static, API, proxy, WebSocket)
├── middleware/        # CORS, security headers, rate limiting
├── monitoring/        # Health checks, metrics, certificate monitoring
├── server/            # Server infrastructure
└── ssl/               # SSL/TLS and certificate management

CLI Options

bws                                  # Use config.toml  
bws --config custom.toml             # Custom config file
bws /path/to/directory               # Serve directory directly
bws /path/to/directory --port 8080   # Custom port
bws --verbose                        # Enable debug logging
bws --daemon                         # Background process (Unix only)
bws --dry-run                        # Validate configuration

Configuration Validation

Validate before deployment:

# Validate configuration
bws --config config.toml --dry-run

# Validate before starting
bws --config production.toml --dry-run && bws --config production.toml

The validator checks:

  • TOML syntax and schema compliance
  • Static directories and index files
  • SSL certificates and ACME settings
  • Proxy upstream configurations
  • Port conflicts and virtual hosting setup

Hot Reload

Update configuration without restarting:

# Reload via API
curl -X POST http://localhost:8080/api/reload

# Using signals (Unix)
kill -HUP $(pgrep -f "bws.*master")

What can be reloaded:

  • Site configurations and hostnames
  • SSL certificates and ACME settings
  • Proxy routes and upstreams
  • Static file directories
  • Security headers

Note: Server ports require restart.

API Endpoints

BWS provides monitoring and management APIs:

  • GET /api/health - Server health status
  • GET /api/health/detailed - Detailed system information
  • GET /api/sites - List configured sites
  • POST /api/reload - Hot reload configuration

Example:

curl http://localhost:8080/api/health
curl http://localhost:8080/api/sites | jq
curl -X POST http://localhost:8080/api/reload

Docker

# Quick start
docker run -d -p 8080:8080 ghcr.io/benliao/bws:latest

# With custom config
docker run -d \
  -p 8080:8080 \
  -v $(pwd)/config.toml:/app/config.toml:ro \
  -v $(pwd)/static:/app/static:ro \
  ghcr.io/benliao/bws:latest

Security

  • Memory Safety: Rust prevents buffer overflows and memory leaks
  • Zero Panics: Comprehensive error handling throughout
  • Security Headers: HSTS, CSP, XSS protection built-in
  • Path Traversal Protection: Secure static file serving
  • Rate Limiting: Configurable request throttling

Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/name)
  3. Commit your changes (git commit -m 'Add feature')
  4. Push to the branch (git push origin feature/name)
  5. Open a Pull Request

License

Licensed under the MIT License.


BWS - Enterprise-grade web serving, simplified.

About

BWS (Blazing Web Server) is a production-ready web server and reverse proxy that prioritizes memory safety and performance. Built on Cloudflare's Pingora framework with Rust's ownership model, BWS eliminates entire classes of security vulnerabilities while delivering enterprise-grade performance.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages