1
0
mirror of https://github.com/umputun/reproxy.git synced 2024-11-24 08:12:31 +02:00
reproxy/README.md

165 lines
9.4 KiB
Markdown
Raw Normal View History

2021-04-10 02:31:39 +02:00
# reproxy [![build](https://github.com/umputun/reproxy/actions/workflows/ci.yml/badge.svg)](https://github.com/umputun/reproxy/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/umputun/reproxy/badge.svg?branch=master)](https://coveralls.io/github/umputun/reproxy?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/umputun/reproxy)](https://goreportcard.com/report/github.com/umputun/reproxy) [![Docker Automated build](https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg)](https://hub.docker.com/repository/docker/umputun/reproxy)
2021-04-10 01:03:35 +02:00
2021-03-28 23:05:47 +02:00
2021-04-12 23:12:14 +02:00
Reproxy is simple edge HTTP(s) server / reverse proxy supporting various providers (docker, static, file).
2021-04-10 00:56:45 +02:00
One or more providers supply information about requested server, requested url, destination url and health check url.
Distributed as a single binary or as a docker container.
2021-04-03 09:31:48 +02:00
2021-04-11 04:23:07 +02:00
Server can be set as FQDN, i.e. `s.example.com` or `*` (catch all). Requested url can be regex, for example `^/api/(.*)` and destination url may have regex matched groups in, i.e. `http://d.example.com:8080/$1`. For the example above `http://s.example.com/api/something?foo=bar` will be proxied to `http://d.example.com:8080/something?foo=bar`.
2021-04-03 09:31:48 +02:00
2021-04-10 01:00:10 +02:00
For convenience, requests with the trailing `/` and without regex groups expanded to `/(.*)`, and destinations in those cases
2021-04-10 00:48:22 +02:00
expanded to `/$1`. I.e. `/api/` -> `http://127.0.0.1/service` will be translated to `^/api/(.*)` -> `http://127.0.0.1/service/$1`
2021-04-10 01:00:10 +02:00
Both HTTP and HTTPS supported. For HTTPS, static certificate can be used as well as automated ACME (Let's Encrypt) certificates.
Optional assets server can be used to serve static files.
2021-04-03 09:31:48 +02:00
2021-04-10 00:48:22 +02:00
Starting reproxy requires at least one provider defined. The rest of parameters are strictly optional and have sane default.
2021-04-03 09:31:48 +02:00
2021-04-10 02:33:25 +02:00
example with a static provider:
2021-04-10 08:50:20 +02:00
`reproxy --static.enabled --static.rule="example.com/api/(.*),https://api.example.com/$1"`
2021-04-03 09:31:48 +02:00
2021-04-10 00:56:45 +02:00
## Install
2021-04-11 04:23:07 +02:00
- for a binary distribution pick the proper file in the [release section](https://github.com/umputun/reproxy/releases)
2021-04-10 00:56:45 +02:00
- docker container available via docker hub (umputun/reproxy) as well as via github container registry (ghcr.io/umputun/reproxy). Latest stable version has `:vX.Y.Z` tag (with `:latest` alias) and the current master has `:master` tag.
2021-04-03 09:31:48 +02:00
## Providers
2021-04-10 00:48:22 +02:00
User can sets multiple providers at the same time.
2021-04-10 20:18:28 +02:00
_See examples of various providers in [examples](https://github.com/umputun/reproxy/tree/master/examples)_
2021-04-03 09:31:48 +02:00
### Static
2021-04-10 00:48:22 +02:00
This is the simplest provider defining all mapping rules directly in the command line (or environment). Multiple rules supported.
Each rule is 3 or 4 comma-separated elements `server,sourceurl,destination,[ping-url]`. For example:
2021-04-03 09:31:48 +02:00
2021-04-11 04:23:07 +02:00
- `*,^/api/(.*),https://api.example.com/$1,` - proxy all request to any host/server with `/api` prefix to `https://api.example.com`
- `example.com,/foo/bar,https://api.example.com/zzz,https://api.example.com/ping` - proxy all requests to `example.com` and with `/foo/bar` url to `https://api.example.com/zzz`. Uses `https://api.example.com/ping` for the health check
2021-04-03 09:31:48 +02:00
2021-04-10 02:34:27 +02:00
The last (4th) element defines an optional ping url used for health reporting. I.e.`*,^/api/(.*),https://api.example.com/$1,https://api.example.com/ping`. See [Health check](https://github.com/umputun/reproxy#ping-and-health-checks) section for more details.
2021-04-10 00:48:22 +02:00
### File
2021-04-03 09:31:48 +02:00
2021-04-04 02:24:22 +02:00
`reproxy --file.enabled --file.name=config.yml`
2021-04-03 09:31:48 +02:00
example of `config.yml`:
```yaml
2021-04-10 00:48:22 +02:00
default: # the same as * (catch-all) server
- {route: "^/api/svc1/(.*)", dest: "http://127.0.0.1:8080/blah1/$1"}
- {route: "/api/svc3/xyz", dest: "http://127.0.0.3:8080/blah3/xyz", "ping": "http://127.0.0.3:8080/ping"}
srv.example.com:
- {route: "^/api/svc2/(.*)", dest: "http://127.0.0.2:8080/blah2/$1/abc"}
2021-04-03 09:31:48 +02:00
```
2021-04-10 00:48:22 +02:00
This is a dynamic provider and file change will be applied automatically.
### Docker
Docker provider supports a fully automatic discovery (with `--docker.auto`) with no extra configuration and by default redirects all requests like `https://server/<container_name>/(.*)` to the internal IP of the given container and the exposed port. Only active (running) containers will be detected.
2021-04-10 00:48:22 +02:00
This default can be changed with labels:
2021-04-12 10:41:04 +02:00
- `reproxy.server` - server (hostname) to match. Also can be a list of comma-separated servers.
- `reproxy.route` - source route (location)
- `reproxy.dest` - destination path. Note: this is not full url, but just the path which will be appended to container's ip:port
- `reproxy.ping` - ping path for the destination container.
- `reproxy.enabled` - enable (`yes`, `true`, `1`) or disable (`no`, `false`, `0`) container from reproxy destinations.
Pls note: without `--docker.auto` the destination container has to have at least one of `reproxy.*` labels to be considered as a potential destination.
With `--docker.auto`, all containers with exposed port will be considered as routing destinations. There are 3 ways to restrict it:
- Exclude some containers explicitly with `--docker.exclude`, i.e. `--docker.exclude=c1 --docker.exclude=c2 ...`
- Allow only a particular docker network with `--docker.network`
- Set the label `reproxy.enabled=false` or `reproxy.enabled=no` or `reproxy.enabled=0`
2021-04-10 00:48:22 +02:00
This is a dynamic provider and any change in container's status will be applied automatically.
## SSL support
SSL mode (by default none) can be set to `auto` (ACME/LE certificates), `static` (existing certificate) or `none`. If `auto` turned on SSL certificate will be issued automatically for all discovered server names. User can override it by setting `--ssl.fqdn` value(s)
## Logging
By default no request log generated. This can be turned on by setting `--logger.enabled`. The log (auto-rotated) has [Apache Combined Log Format](http://httpd.apache.org/docs/2.2/logs.html#combined)
## Assets Server
User may turn assets server on (off by default) to serve static files. As long as `--assets.location` set it will treat every non-proxied request under `assets.root` as a request for static files.
Assets server can be used without any proxy providers. In this mode reproxy acts as a simple web server for a static context.
2021-04-10 00:48:22 +02:00
## More options
- `--gzip` enables gizp compression for responses.
- `--max=N` allows to set the maximum size of request (default 64k)
- `--header` sets extra header(s) added to each proxied request
2021-04-10 00:56:45 +02:00
## Ping and health checks
reproxy provides 2 endpoints for this purpose:
- `/ping` responds with `pong` and indicates what reproxy up and running
- `/health` returns `200 OK` status if all destination servers responded to their ping request with `200` or `417 Expectation Failed` if any of servers responded with non-200 code. It also returns json body with details about passed/failed services.
2021-04-10 00:48:22 +02:00
## All Application Options
2021-04-01 09:53:42 +02:00
```
2021-04-03 09:31:48 +02:00
-l, --listen= listen on host:port (default: 127.0.0.1:8080) [$LISTEN]
-t, --timeout= proxy timeout (default: 5s) [$TIMEOUT]
2021-04-10 00:48:22 +02:00
-m, --max= max response size (default: 64000) [$MAX_SIZE]
2021-04-03 09:31:48 +02:00
-g, --gzip enable gz compression [$GZIP]
-x, --header= proxy headers [$HEADER]
2021-04-10 00:48:22 +02:00
--no-signature disable reproxy signature headers [$NO_SIGNATURE]
2021-04-03 09:31:48 +02:00
--dbg debug mode [$DEBUG]
ssl:
--ssl.type=[none|static|auto] ssl (auto) support (default: none) [$SSL_TYPE]
--ssl.cert= path to cert.pem file [$SSL_CERT]
--ssl.key= path to key.pem file [$SSL_KEY]
--ssl.acme-location= dir where certificates will be stored by autocert manager (default: ./var/acme) [$SSL_ACME_LOCATION]
--ssl.acme-email= admin email for certificate notifications [$SSL_ACME_EMAIL]
2021-04-10 00:48:22 +02:00
--ssl.http-port= http port for redirect to https and acme challenge test (default: 80) [$SSL_HTTP_PORT]
--ssl.fqdn= FQDN(s) for ACME certificates [$SSL_ACME_FQDN]
2021-04-01 09:53:42 +02:00
assets:
2021-04-03 09:31:48 +02:00
-a, --assets.location= assets location [$ASSETS_LOCATION]
--assets.root= assets web root (default: /) [$ASSETS_ROOT]
2021-04-01 09:53:42 +02:00
2021-04-10 00:48:22 +02:00
logger:
--logger.enabled enable access and error rotated logs [$LOGGER_ENABLED]
--logger.file= location of access log (default: access.log) [$LOGGER_FILE]
--logger.max-size= maximum size in megabytes before it gets rotated (default: 100) [$LOGGER_MAX_SIZE]
--logger.max-backups= maximum number of old log files to retain (default: 10) [$LOGGER_MAX_BACKUPS]
2021-04-01 09:53:42 +02:00
docker:
2021-04-03 09:31:48 +02:00
--docker.enabled enable docker provider [$DOCKER_ENABLED]
--docker.host= docker host (default: unix:///var/run/docker.sock) [$DOCKER_HOST]
--docker.network= docker network [$DOCKER_NETWORK]
2021-04-03 09:31:48 +02:00
--docker.exclude= excluded containers [$DOCKER_EXCLUDE]
--docker.auto enable automatic routing (without labels) [$DOCKER_AUTO]
2021-04-01 09:53:42 +02:00
file:
2021-04-03 09:31:48 +02:00
--file.enabled enable file provider [$FILE_ENABLED]
2021-04-10 00:48:22 +02:00
--file.name= file name (default: reproxy.yml) [$FILE_NAME]
2021-04-03 09:31:48 +02:00
--file.interval= file check interval (default: 3s) [$FILE_INTERVAL]
--file.delay= file event delay (default: 500ms) [$FILE_DELAY]
2021-04-01 09:53:42 +02:00
static:
2021-04-03 09:31:48 +02:00
--static.enabled enable static provider [$STATIC_ENABLED]
--static.rule= routing rules [$STATIC_RULES]
2021-04-01 09:53:42 +02:00
Help Options:
2021-04-03 09:31:48 +02:00
-h, --help Show this help message
2021-04-10 00:48:22 +02:00
```
## Status
The project is under active development and may have breaking changes till `v1` released.