Rustyx is a minimal reverse proxy written in Rust, inspired by NGINX. It routes HTTP traffic to multiple backends based on the request path, adds headers like X-Forwarded-For, and uses a simple .toml file for configuration.
- Multi-server configuration: Support for multiple proxy servers with different listening addresses
- Path-based routing: Route requests to different backend servers based on URL paths
- Graceful Shutdown: Support for a "graceful shutdown" signal.
- HTTP/HTTPS tunneling: Full support for CONNECT method and SSL tunneling
- Async architecture: Built on Tokio for high concurrency and performance
- Header preservation: Maintains original header casing and formatting
- Connection upgrades: Support for WebSocket and other protocol upgrades
- Rust 1.70+ (2024 edition)
- Cargo
git clone git@github.com:Joelp03/rustyx.git
cd rustyx
cargo build --releaseRustyx uses a TOML configuration file (rustyx.toml) to define proxy servers and routing rules.
# Primary server
[[server]]
listen = ["127.0.0.1:8000"]
name = "localhost"
[[server.location]]
path = "/"
proxy_pass = "127.0.0.1:9000"
[[server.location]]
path = "/api"
proxy_pass = "127.0.0.1:9001"
# Additional server
[[server]]
listen = ["127.0.0.1:8080", "0.0.0.0:8080"]
name = "public"
# static files
[[server.location]]
path = "/"
root = "/home/joel/Documents/Development/projects/Rustyx/public"listen: Array of socket addresses to bind the proxy servername: Human-readable name for the server instancelocation: Array of routing rulespath: URL path prefix to matchproxy_pass: Backend server address to forward requests
- Create your
rustyx.tomlconfiguration file - Run the proxy server:
cargo runOr with the release build:
./target/release/rustyx- Master: Main orchestrator that manages multiple server instances
- ProxyService: HTTP service implementation handling request routing
- Config: TOML-based configuration management
- HTTP modules: Request/response handling and forwarding
- Client connects to a configured listening address
- Rustyx accepts the connection and spawns a task
- Incoming requests are matched against location paths
- Requests are forwarded to the appropriate backend server
- Responses are proxied back to the client
The proxy uses longest-prefix matching for path routing. For example:
- Request to
/api/usersmatches/apiover/ - Request to
/app/dashboardmatches/appif configured
Rustyx/
├── Cargo.toml # Project dependencies and metadata
├── Cargo.lock # Dependency lock file
├── README.md # Project documentation
├── rustyx.toml # Proxy server configuration
├── .gitignore # Git ignore rules
│
├── src/ # Source code
│ ├── main.rs # Application entry point with graceful shutdown
│ ├── rustyx.rs # Master server orchestrator
│ │
│ ├── config/ # Configuration management
│ │ ├── mod.rs # Module exports
│ │ └── config.rs # TOML config parsing and structures
│ │
│ ├── handlers/ # Request handlers
│ │ ├── mod.rs # Module exports
│ │ ├── proxy.rs # Refactored proxy service with routing
│ │ └── serve_file.rs # Enhanced static file server with security
│ │
│ └── http/ # HTTP utilities and abstractions
│ ├── mod.rs # Module exports
│ ├── body.rs # HTTP body utilities (full, empty, not_found)
│ ├── request.rs # Proxy request wrapper
│ └── response.rs # Proxy response wrapper
│
- hyper: HTTP implementation
- hyper-util: HTTP utilities and runtime
- tokio: Async runtime
- serde: Serialization framework
- toml: TOML parsing
cargo testFor development with auto-reload:
cargo watch -x runRustyx is designed for high performance with:
- Zero-copy request forwarding where possible
- Async I/O throughout the stack
- Efficient connection pooling
- Minimal memory allocations
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
[Add your license information here]
- HTTPS support
- Load balancing support
- Hot configuration reload
- Health checks for backend servers