| Crates.io | reverse-http-proxy |
| lib.rs | reverse-http-proxy |
| version | 0.1.0 |
| created_at | 2025-10-30 18:56:30.240225+00 |
| updated_at | 2025-10-30 18:56:30.240225+00 |
| description | A minimal reverse proxy for path-based HTTP routing with optional URL rewriting |
| homepage | https://github.com/jvtubergen/reverse-http-proxy |
| repository | https://github.com/jvtubergen/reverse-http-proxy |
| max_upload_size | |
| id | 1908774 |
| size | 29,918 |
A minimal reverse proxy for path-based HTTP routing.
A lightweight, high-performance reverse proxy written in Rust. Routes HTTP requests to different backend servers based on URL paths using efficient bidirectional binary streaming with minimal overhead.
Note: URL path rewriting is available via the --rewrite flag (disabled by default). When disabled, the complete original path is forwarded unchanged to the backend server.
# Basic usage with default backend only
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000
# With path-based routing
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000 \
-r /api=127.0.0.1:4000 \
-r /webhook=127.0.0.1:5000
In this example:
0.0.0.0:8080/api/* go to 127.0.0.1:4000/webhook/* go to 127.0.0.1:5000127.0.0.1:3000You'll need Rust installed. Get it from rustup.rs.
cd reverse-http-proxy
cargo build --release
The binary will be at target/release/reverse-http-proxy.
reverse-http-proxy <LISTEN_ADDRESS> <DEFAULT_BACKEND> [OPTIONS]
LISTEN_ADDRESS - Address to listen on (format: ip:port)DEFAULT_BACKEND - Default backend address for unmatched paths (format: ip:port)-r, --route <PATH=BACKEND> - Add a path-based route (can be specified multiple times)
/path=ip:port/--rewrite - Enable path rewriting (strips matched route prefix from forwarded requests)reverse-http-proxy 0.0.0.0:80 127.0.0.1:3000 \
-r /api/v1=127.0.0.1:4001 \
-r /api/v2=127.0.0.1:4002 \
-r /admin=127.0.0.1:5000 \
-r /static=127.0.0.1:6000
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000 \
-r /users=127.0.0.1:4001 \
-r /orders=127.0.0.1:4002 \
-r /payments=127.0.0.1:4003
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000 \
-r /webhook/github=127.0.0.1:5000 \
-r /webhook/stripe=127.0.0.1:5001 \
-r /webhook/slack=127.0.0.1:5002
The proxy uses longest prefix matching for routing:
Given these routes:
-r /api=backend1:4000 \
-r /api/v2=backend2:5000 \
-r /webhook=backend3:6000
Request routing:
GET / → default backendGET /api → backend1:4000 (exact match)GET /api/users → backend1:4000 (prefix match)GET /api/v2/users → backend2:5000 (longest prefix match wins)GET /webhook/stripe → backend3:6000 (prefix match)GET /other → default backend (no match)By default, the complete original path is forwarded to the backend server unchanged. You can enable path rewriting with the --rewrite flag to strip the matched route prefix.
With route -r /api=127.0.0.1:4000:
GET /api/usersGET /api/users (unchanged)--rewrite)With route -r /api=127.0.0.1:4000 --rewrite:
GET /api/usersGET /users (prefix stripped)Examples:
# Without rewriting (default)
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000 -r /api=127.0.0.1:4000
# Request to /api/test -> backend receives /api/test
# With rewriting
reverse-http-proxy 0.0.0.0:8080 127.0.0.1:3000 -r /api=127.0.0.1:4000 --rewrite
# Request to /api/test -> backend receives /test
Path rewriting behavior:
/The proxy operates in these key steps:
By forwarding raw TCP bytes after initial routing, it achieves high performance while supporting any HTTP protocol version transparently.