An nginx reverse proxy and redirect server, configured for common purposes with a simplified config.yml
file.
It is expected that you will run this behind Traefik for automated SSL via Let's Encrypt.
The config.yml
file represents one or more templated server
blocks and one or more templated location
blocks within each server
block.
Each location can be configured to reverse proxy, 301 permanent redirect, or 302 temporary redirect.
- server_name: # Nginx `server_name` directive
client_max_body_size: # Nginx `client_max_body_size` diretive.
locations:
- rule: # Nginx `location` directive. Default: /
url: # Nginx `proxy_pass` or `return` directive.
permanent: # Return 301 permanent (true) or 302 temporary (false) redirect. Default: false
proxy: # Reverse proxy (true) or redirect (false). Default: false
proxy_hostname: # Set Host header for proxy requests. Default: $http_host
Keys with default values can be omitted.
Locations and redirect URLs can include regular expressions and capture groups. Order matters when using regular expressions.
Append $uri
to your redirect URL for a "soft" redirect, or use a regular expression location with capture groups to strip or rewrite part of the location from the redirect URL.
You can configure nginx with the following environment variables:
CLIENT_MAX_BODY_SIZE='10m'
- A default value, declared in thehttp
block. Can be overridden in eachserver
block viaconfig.yml
.WORKER_PROCESSES='1'
- A value ofauto
will run one worker process per available CPU core.
Some nginx config is hard coded:
- Log to stdout/stderr.
- Gzip is enabled for common text formats.
- Websockets are supported.
- Pass headers:
X-Forwarded-Proto
. - Set headers:
X-Forwarded-For
. - Get real IP from trusted proxies (with private IP addresses).
Additional nginx configs are included from data/conf.d/*.conf
, at the end of the http
block. Use this to create custom server
blocks with arbitrary config, if the proxy and redirect config templates are insufficient.
Here are some quick links to the nginx docs for directives you can configure via config.yml
:
Example config.yml
and docker-compose.yml
files are provided for testing. In production, you should provide your configs in a bind mounted directory to /opt/nginx-proxy-redirect/data
.