A simple and ultrafast http reverse proxy serving multiple domain names and terminating TLS for http/1.1, 2 and 3, written in Rust
A simple and ultrafast http reverse proxy serving multiple domain names and terminating TLS for http/1.1, 2 and 3, written in Rust
Work-in-progress project that is being evolved.
[!NOTE] This project is an HTTP (i.e., Layer 7) reverse-proxy. If you are looking for a TCP/UDP (i.e., Layer 4) reverse-proxy, please check my other project
rpxy-l4.
[!NOTE] If
rpxyand our other projects likerpxy-l4are useful for you and your organization, please consider sponsoring us on GitHub Sponsors to help sustain the project. We are also open to any kind of support, including donations and commercial agreements.
rpxy [ahr-pik-see] is a simple and lightweight reverse-proxy implementation with additional features. The implementation is based on hyper, rustls and tokio, i.e., written in Rust [^pure_rust]. rpxy routes multiple hostnames to appropriate backend application servers while serving TLS connections.
[^pure_rust]: It is questionable whether this can be claimed to be written in pure Rust since the current rpxy is based on aws-lc-rs for cryptographic operations.
The supported features are summarized as follows:
rpxy-l4)[^h3lib]: HTTP/3 is enabled thanks to quinn, s2n-quic and hyperium/h3. HTTP/3 libraries are mutually exclusive. You need to explicitly specify s2n-quic with --no-default-features flag. Also note that if you build rpxy with s2n-quic, then it requires openssl just for building the package.
[^acme]: rpxy supports the automatic issuance and renewal of certificates via TLS-ALPN-01 (RFC8737) of ACME protocol (RFC8555) thanks to rustls-acme.
[^kyber]: rpxy supports the hybridized post-quantum key exchange X25519MLKEM768 for TLS/QUIC incoming and outgoing initiation thanks to rustls's aws-lc-rs crypto provider with the prefer-post-quantum feature. This is already a default feature. Also note that X25519MLKEM768 is still a draft version yet this is widely used on the Internet.
[^sanitization]: By default, rpxy provides TLS connection sanitization by correctly binding a certificate used to establish a secure channel with the backend application. Specifically, it always maintains consistency between the given SNI (server name indication) in ClientHello of the underlying TLS and the domain name given by the overlaid HTTP HOST header (or URL in Request line). We should note that NGINX doesn't guarantee such consistency by default. To achieve this, you have to add an if statement in the NGINX configuration file.
This project is still work-in-progress. However, it is already working in some production environments and serves a number of domain names. The bench directory provides a reverse-proxy benchmarking harness you can run on your own target; note that reverse-proxy performance is highly dependent on hardware, configuration, and environment, so we make no performance-ranking claim here (see the caveat in bench/README.md).
rpxyYou can build an executable binary yourself by checking out this Git repository.
# Cloning the git repository
% git clone https://github.com/junkurihara/rust-rpxy
% cd rust-rpxy
# Update submodules
% git submodule update --init
# Build (default: QUIC and HTTP/3 is enabled using `quinn`)
% cargo build --release
# If you want to use `s2n-quic`, build as follows. You may need several additional dependencies.
% cargo build --no-default-features --features http3-s2n --releaseThen you have an executable binary rust-rpxy/target/release/rpxy.
[!NOTE] At this point, it can be built only on Linux, macOS and some Unix-like OSes (#150, #478). If you want to use
rpxyon Windows, please consider using the docker image (see below) as a workaround.
[!NOTE] We do not have an installation option via
crates.io, i.e.,cargo install, at this point since some dependencies are not yet published. Alternatively, you can use the docker image (see below) as the easiest way foramd64environments.
You can find the Jenkins CI/CD build scripts for rpxy in the ./.build directory.
Prebuilt packages
Prebuilt packages for Linux RPM and DEB are available at https://rpxy.gamerboy59.dev, provided by @Gamerboy59.
Warning: These packages are built and distributed by a third party, and they may lag behind the latest release of rpxy, sometimes by several versions. Since new releases often include security-related fixes and improvements, please check the packaged version before installation. To always run the latest release, use the prebuilt binaries on the GitHub Releases page or the docker image (see below).
rpxy always refers to a configuration file in TOML format, e.g., config.toml. You can find an example of the configuration file, config-example.toml, in this repository.
You can run rpxy with a configuration file like
% ./target/release/rpxy --config config.tomlrpxy tracks changes to config.toml in real-time and applies changes immediately without restarting the process. Note that if config.toml is removed, renamed or moved (including moving to trash), rpxy continues running with the last valid configuration until a new file named config.toml is created in the same directory.
The full help message is as follows.
usage: rpxy [OPTIONS] --config
Options:
-c, --config Configuration file path like ./config.toml
-l, --log-dir Directory for log files. If not specified, logs are printed to stdout.
-h, --help Print help
-V, --version Print versionIf you set --log-dir=, the log files are created in the specified directory. Otherwise, the log is printed to stdout.
${log_dir}/access.log for access log
${log_dir}/rpxy.log for system and error log
The log verbosity is controlled by the RUST_LOG environment variable (e.g., RUST_LOG=debug). At debug level, the request-forwarding log redacts the values of sensitive headers (Authorization, Cookie, Proxy-Authorization) as ``. For troubleshooting only, you can disable this redaction by setting RPXY_UNSAFE_DEBUG_HEADERS to 1, true, or yes; rpxy then prints these header values verbatim and emits a warning at startup. This is read once at startup and must not be left enabled in production.
The access log line includes the request host, client address, method, path and query string, HTTP version, status, a reconstructed request URL (scheme, host, and path only, without the query string), User-Agent, X-Forwarded-For, Forwarded, and the upstream URL. Because query strings can carry tokens or personal data (e.g. ?token=..., ?email=...), you can set the global option redact_query_in_access_log = true in config.toml to mask query-string values (the keys and path are kept, values become ``) in both the request path+query and the upstream URL. It defaults to false, preserving full query logging.
That's all!
The most basic configuration of config.toml is given like the following.
listen_port = 80
[apps.app1]
server_name = 'app1.example.com'
reverse_proxy = [{ upstream = [{ location = 'app1.local:8080' }] }]In the above setting, rpxy listens on port 80 (TCP) and serves incoming cleartext HTTP requests that include app1.example.com in their HOST header or URL in their Request line.
For example, request messages like the following.
GET http://app1.example.com/path/to HTTP/1.1\r\nor
GET /path/to HTTP/1.1\r\n
HOST: app1.example.com\r\nOtherwise, a request to other.example.com is simply rejected with status code 40x.
If you want to host multiple distinct domain names on a single IP address/port, simply create multiple app."" entries in the config file like
default_app = "app1"
[apps.app1]
server_name = "app1.example.com"
#...
[apps.app2]
server_name = "app2.example.org"
#...[!NOTE] Note that by specifying a
default_appentry, HTTP requests will be served by the specified application if the HOST header or URL in the Request line doesn't match anyserver_names inreverse_proxyentries. For HTTPS requests, it will be rejected since a secure connection cannot be established for an unknown server name. [^https-default-app-rejection]
Request Header Rewriting for Default Application
When a request falls through to the default_app, rpxy rewrites the outgoing request headers to prevent the untrusted Host from reaching the backend:
Host header sent upstream is force-overwritten with the default application's configured server_name. This overwrite is stronger than the keep_original_host / set_upstream_host upstream options, because the incoming Host is, by definition, unknown to rpxy on this path.X-Forwarded-Host are rebuilt separately by the general forwarding-header policy. On the fallback path, this means the backend sees an authoritative rewritten Host together with forwarding metadata that still reflects the original client-visible host.rpxy, X-Forwarded-Host and Forwarded: host= are observational only and MUST NOT be used for security decisions (tenant routing, trusted-host allowlists, absolute URL generation, etc.).[^https-default-app-rejection]: This rejection is unconditional and does not depend on sni_consistency.
The request message will be routed to the backend application specified with the domain name app1.localdomain:8080 or IP address over cleartext HTTP. If the backend channel needs to serve TLS, like forwarding to https://app1.localdomain:8080, you need to enable the tls option for the location.
reverse_proxy = [
{ location = 'app1.localdomain:8080', tls = true }
]You can specify multiple backend locations in the reverse_proxy array for load-balancing with an appropriate load_balance option. Currently it works in a round-robin manner, randomly, or round-robin with session-persistence using cookies. If load_balance is not specified, the first backend location is always chosen.
# Required only when any reverse_proxy uses load_balance = 'sticky'.
# Generate with: openssl rand -base64 32 | tr '+/' '-_' | tr -d '=\n'
sticky_cookiNo open issues yet, or sync has not completed.