HTTPS for your domains on your own servers, with certificates RedirHub issues and renews.
1.1K
HTTPS, redirects and 404 reports for your domains on your own servers. RedirHub issues and renews every certificate and syncs it to each server that runs this container, along with the links you add to those domains; visitors reach your servers directly and never pass through RedirHub.
Just HTTPS? Add no links to the domain: every request then goes straight to your app.
Published as redirhub/edge on Docker Hub (and ghcr.io/redirhub/self-hosted-tls), for amd64 and
arm64.
Copy the command from your domain's setup in the RedirHub dashboard (it has your token in it), or:
docker run -d --name redirhub-edge --restart unless-stopped --network host \
-v redirhub-edge:/data \
-e REDIRHUB_TOKEN=<your workspace token> \
redirhub/edge
That is all a usual server needs: the container takes port 443, answers HTTPS for your domains and passes every request to your app on port 80, which keeps serving as before. Run the same command, with the same token, on every server, then point your domains' A (and AAAA) records at them.
--network host: the container listens on the server's own ports, and 127.0.0.1 is the server,
so your app is reachable without any Docker networking.-v redirhub-edge:/data: keeps the server's identity and certificates across restarts and
upgrades. Keep the volume when you update the image; a new volume registers a new server.Every setting is an environment variable (-e NAME=value). Only the token is required.
| Setting | Default | What it does |
|---|---|---|
REDIRHUB_TOKEN | (required) | Your workspace's server token. It lets the server fetch your workspace's certificates, and nothing else, and prove your domains. |
UPSTREAM | http://127.0.0.1:80 | Where your app listens. Every request goes there once TLS is done, with X-Forwarded-For and X-Real-IP (the visitor's address; one a visitor sends is replaced), X-Forwarded-Proto and X-Forwarded-Host. http:// or https://, on this server or another one. |
PORT_HTTPS | 443 | The port the container takes for HTTPS. Change it only when something in front (a TCP load balancer passing TLS through) sends port 443 here: Let's Encrypt and our checks reach your domains on 443. |
PORT_HTTP | off | A port for plain HTTP, e.g. 80. off leaves port 80 (and every other port) to your app. |
ALWAYS_HTTPS | on | What plain HTTP on PORT_HTTP gets. on sends every request to HTTPS (301). off serves it as HTTPS is served (your links, then your app), with X-Forwarded-Proto: http. |
LINKS | on | off serves no links on these servers: HTTPS only, every request goes to your app. The servers still keep the links in their copy, so turning it on again (and restarting the container) serves them at once. |
REPORT_404 | on | off reports none of your app's 404s from these servers. (Each domain can also turn 404 reports off in RedirHub.) |
PORT_HEALTH | off | A port for a load balancer's health check: GET /ready answers 200 ready once the server holds your certificates, 503 loading before. It stays 200 while RedirHub cannot be reached, as the server keeps serving. Nothing else is served on it. |
PROXY_PROTOCOL | off | Behind a TCP load balancer that sends the PROXY protocol (v1 or v2): your balancers' addresses or ranges, e.g. 10.0.0.0/8 or 10.0.1.5,10.0.2.5 (all for any source). Your app then gets the visitor's address, not the balancer's. Only these addresses may connect to PORT_HTTPS, and only their header counts on PORT_HTTP. |
EDGE_SYNC_LISTEN | 127.0.0.1:18090 | Where the sync process answers its status (/status, /ready, used by Docker's health check, which turns unhealthy while the server is out of date). Move it if your server already uses that port. |
REDIRHUB_API | https://api.redirhub.com | The RedirHub API. Leave it as it is. |
The container refuses to start, and says why, when a setting has a value it does not know.
Your app on another port. Point UPSTREAM at it:
-e UPSTREAM=http://127.0.0.1:8080
Nothing else on port 80. Let the container send plain HTTP to HTTPS:
-e PORT_HTTP=80
Port 80 should keep reaching your app through the container. For an app that only listens on another port:
-e UPSTREAM=http://127.0.0.1:8080 -e PORT_HTTP=80 -e ALWAYS_HTTPS=off
Behind a TCP load balancer. Pass TLS through (no termination) from the balancer's port 443 to
the container's PORT_HTTPS, and point the balancer's health check at PORT_HEALTH. Turn on the
PROXY protocol on the balancer and name it in PROXY_PROTOCOL so your app sees the visitor's
address (without it, X-Forwarded-For holds the balancer's):
-e PORT_HTTPS=8443 -e PORT_HEALTH=8091 -e PROXY_PROTOCOL=10.0.0.0/8
The visitor's address is a header only once TLS has ended: a TCP balancer that passes TLS through cannot write into the encrypted request, so it puts the address in a PROXY header in front of it, which the container reads. An HTTP (layer 7) load balancer in front does not work: TLS has to end in the container, which answers Let's Encrypt's TLS-ALPN-01 challenges.
Docker Compose.
services:
edge:
image: redirhub/edge
container_name: redirhub-edge
restart: unless-stopped
network_mode: host
environment:
REDIRHUB_TOKEN: ${REDIRHUB_TOKEN}
volumes:
- redirhub-edge:/data
volumes:
redirhub-edge:
The parts of the OpenResty config you may want to change live in /etc/edge/; mount
your own files there. TLS, certificates, the links and the health check stay the image's.
| Path | What it is |
|---|---|
proxy.conf | How a request reaches your app: proxy_pass, headers, timeouts. The image writes it from UPSTREAM; a file of yours replaces it whole. |
http.d/*.conf | Added to the http block: an upstream with several app servers, a map, a limit_req_zone. |
server.d/*.conf | Added to the servers that serve your domains (HTTPS, and plain HTTP): headers such as HSTS, extra location blocks (not location /). |
-v /srv/edge/proxy.conf:/etc/edge/proxy.conf:ro \
-v /srv/edge/http.d:/etc/edge/http.d:ro \
-v /srv/edge/server.d:/etc/edge/server.d:ro
For example, two app servers behind one domain:
# http.d/app.conf
upstream app { server 10.0.0.11:8080; server 10.0.0.12:8080; }
# proxy.conf
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
The container checks the config before it starts, and refuses to start, naming the line, when a
file of yours does not load. Start from the proxy.conf your container wrote:
docker exec redirhub-edge cat /usr/local/openresty/nginx/conf/proxy.conf.
The links of your self-hosted domains are served by the container, in front of your app, by the same redirector that serves every link on RedirHub's edge. A link behaves here as it does on a domain pointed at RedirHub: redirects of every kind, HTML pages, frames, password-protected links, several destinations with their routing, UTM parameters, bot and in-app-browser filters.
GET and HEAD: a working page is never taken over, and a page your app no longer has goes
where the catch-all says. Without a catch-all, your app's own 404 page reaches the visitor.REPORT_404=off on the servers. Every visit of a link is
reported as well.LINKS=off keeps the servers to HTTPS: no link is served, whatever RedirHub holds.What stays on RedirHub's edge, because it needs the edge itself: the pages RedirHub shows for
links that are not set up, paused or expired (on your domain your app answers instead), and the
JavaScript loader of RedirHub's static pages (/.js is your app's path here). Every redirect
(301, 302, 303, 307, 308), page and frame counts as a visit, and the way on after a password form
too; the form itself does not.
PORT_HTTPS (past the PROXY header, when there
is one) and hands Let's Encrypt's TLS-ALPN-01 challenges to their own handler. Everything else
gets TLS with those certificates; RedirHub's check on /.well-known/host-verification (an HMAC
of the hostname under your token) is answered there.UPSTREAM. The redirector runs in the container on a unix socket
of its own and opens no port. If it stops, it is started again within seconds, and your app
answers every request meanwhile.docker pull redirhub/edge
docker rm -f redirhub-edge
docker run ... (the same command, the same volume)
docker pull redirhub/edge:latest