revpx is a lightweight, single-threaded reverse proxy server for development purposes.
It supports TLS/SSL termination, SNI (Server Name Indication), and can forward traffic to multiple backend services based on the requested domain name.
It is designed to be simple to configure and use.
You can generate the SSL certificate files using mkcert or openssl.
You can specify domain mappings directly on the command line. Each mapping consists of a domain name, a backend port, a certificate file, and a key file.
revpx [<options>] [<domain> <port> <cert_file> <key_file> ...]Options:
--help, -h: Show the help message.--file, -f <path>: Load configuration from a JSON file.--port, -p <port>: The HTTPS port forrevpxto listen on (default: 443).--port-plain, -pp <port>: The HTTP port forrevpxto listen on (default: 80).
Example:
# Forward traffic for example.com to localhost:8080
revpx example.com 8080 /path/to/cert.pem /path/to/key.pemFor more complex setups, you can use a JSON file.
Example revpx.example.json:
[
{
"domain": "example.com",
"port": "8080",
"cert_file": "/path/to/example.com.pem",
"key_file": "/path/to/example.com-key.pem"
},
{
"domain": "api.example.com",
"port": "8081",
"cert_file": "/path/to/api.example.com.pem",
"key_file": "/path/to/api.example.com-key.pem"
}
]Run revpx with the file:
revpx --file revpx.example.jsonThis project depends on OpenSSL and libyaml. Make sure you have the development headers installed (e.g. libssl-dev and libyaml-dev on Debian-based systems).
# Compile the project
make
# Install the binary system-wide (optional)
make installmake: Build the projectmake test: Build and run the testsmake example: Build and run with example domaintest.localhoston port8080make install: Install the binary system-wide in /usr/local/bin
#include "revpx.h"
/**
* Create a new RevPx instance.
* @param http_port Port to listen for HTTP (will redirect to HTTPS)
* @param https_port Port to listen for HTTPS
*/
RevPx *revpx_create(const char *http_port, const char *https_port);
/**
* Free a RevPx instance and all associated resources.
* @param revpx The RevPx instance to free
*/
void revpx_free(RevPx *revpx);
/**
* Add a domain mapping to the reverse proxy.
* @param revpx The RevPx instance
* @param domain The domain name to match (e.g. "example.com")
* @param host The backend host to forward to (default: "127.0.0.1")
* @param port The backend port to forward to
* @param cert The path to the SSL certificate file
* @param key The path to the SSL key file
*/
bool revpx_add_domain(RevPx *revpx, const char *domain, const char *host, const char *port, const char *cert, const char *key);
/**
* Start the reverse proxy server.
* Listens on https_port for HTTPS and redirects HTTP traffic from http_port to HTTPS.
* @param revpx The RevPx instance
* @return 0 on success, non-zero on failure
*/
int revpx_run_server(RevPx *revpx);
/**
* Set the log level for revpx. Messages with a level lower than this will be ignored.
* Default level is RP_INFO.
*/
void revpx_set_log_level(int level);
// Example usage
int main() {
RevPx *revpx = revpx_create("80", "443");
revpx_add_domain(revpx, "test.localhost", NULL, "8080", "test.localhost.pem", "test.localhost-key.pem");
revpx_run_server(revpx);
revpx_free(revpx);
return 0;
}cargo add --git https://github.com/mceck/revpx.gitlet revpx = revpx::RevPx::default();
revpx.add_domains(vec![revpx::DomainConfig {
domain: "test.localhost".to_string(),
host: None,
port: "8080".to_string(),
cert: "test.localhost.pem".to_string(),
key: "test.localhost-key.pem".to_string(),
}]);
revpx.run_server();