Choose a backend server, based on a regex pattern match of your subdomain.
Simple env var configuration.
Inspired by robszumski/k8s-service-proxy
Every proxy rule consist of three or four env variables:
RULE_1_MODE
: <mode>RULE_1_PATTERN
: <regex pattern> (see nginx regex names)RULE_1_TARGET
: <target with usage of pattern variables>RULE_1_TARGET_HOST_HEADER
: <(Optional) modified host header, defaults to TARGET>
Example:
RULE_1_MODE: 'HTTP'
RULE_1_PATTERN: '(?<service>.+).ab.127-0-0-1.nip.io'
RULE_1_TARGET: 'https://$service.ab.example.com'
RULE_2_MODE: 'HTTP'
RULE_2_PATTERN: '(?<service>.+).xy.127-0-0-1.nip.io'
RULE_2_TARGET: 'https://$service.xy.example.com'
RULE_2_TARGET_HOST_HEADER: '$service.modified-host.example.com'
This creates two rules.
The following example requests will get the shown proxy actions:
http://hello.ab.127-0-0-1.nip.io
will proxy pass to
https://hello.ab.example.com
http://world.xy.127-0-0-1.nip.io
will proxy pass to
https://world.xy.example.com
but send the host headerworld.modified-host.example.com
Currently only mode HTTP is implemented
See docker-compose.yml for a docker-compose configuration example.
Be sure to escape all
$
with a$$
inside your env vars. Otherwise docker-compose will try to replace them
Or run without compose:
docker run -p 80:80 --name pattern-proxy \
-e RULE_1_MODE=HTTP \
-e RULE_1_PATTERN='(?<service>.+).ab.127-0-0-1.nip.io' \
-e RULE_1_TARGET='https://$service.ab.example.com' \
kekru/pattern-proxy:v0.1.1
Proxies modes that should be supported:
- HTTP proxy pass
- HTTPS proxy pass
- TLS pass through (non terminating)
- Forward TCP (terminating)
Currently only HTTP proxy pass is implemented
For more information about TLS routing see Nginx TLS SNI routing, based on subdomain pattern
Tests are written in JUnit with Testcontainers and can be run with Maven or with Docker-Compose
cd test
# Run with maven
docker-compose build pattern-proxy && ./mvnw test
# Run with Docker-Compose
docker-compose build && docker-compose run tests