Expand description
Reverse proxy middleware with round-robin load balancing.
ReverseProxy implements Middleware — wrap any application with it and
all matching requests are forwarded to one of the configured backends over
plain HTTP/1.1. Failed backends are skipped and the next one is tried
before returning 502 Bad Gateway.
§Example
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::{LoadBalancing, ReverseProxy};
// Proxy every request across two backends in round-robin order.
let app = App::new()
.wrap(ReverseProxy::new(["http://backend-1:8080", "http://backend-2:8080"])
.strategy(LoadBalancing::RoundRobin));
// Only proxy /api/* requests; everything else is handled locally.
let app2 = App::new()
.wrap(ReverseProxy::new(["http://api-service:3000"])
.path_prefix("/api"));Re-exports§
pub use grpc_web::GrpcWebLayer;pub use pool::ConnPool;pub use pool::Pool;
Modules§
- grpc_
web - gRPC-web to gRPC:
GrpcWebLayerlets browsers (which can’t read HTTP trailers or send HTTP/2 frames of their own) call gRPC services, as Envoy’sgrpc_webfilter does. - pool
Structs§
- Grpc
Proxy - gRPC reverse proxy middleware.
- H2Reverse
Proxy - Reverse proxy that forwards requests to HTTP/2 backends.
- Reverse
Proxy - Reverse proxy middleware.
- Upstream
Tls - Trust settings for one upstream’s TLS backends: the certificates in a CA
file instead of the WebPKI roots — for internal services behind a
private CA or a self-signed certificate (nginx’s
proxy_ssl_trusted_certificate) — and/or a client certificate rws presents to backends that require one (proxy_ssl_certificate, since 18.3.0). Connections are pooled per setting, so two upstreams at the same address with different trust never share one.
Enums§
- Load
Balancing - Load balancing strategy used by
ReverseProxy.