HUB
Sign inSign up

redirhub/edge

By redirhub

•Updated 9 days ago

HTTPS for your domains on your own servers, with certificates RedirHub issues and renews.

Image
0

1.1K

redirhub/edge repository overview

⁠RedirHub Edge (Self-Hosted Edge)

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.

⁠Run it

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.

⁠Settings

Every setting is an environment variable (-e NAME=value). Only the token is required.

SettingDefaultWhat 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.
UPSTREAMhttp://127.0.0.1:80Where 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_HTTPS443The 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_HTTPoffA port for plain HTTP, e.g. 80. off leaves port 80 (and every other port) to your app.
ALWAYS_HTTPSonWhat 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.
LINKSonoff 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_404onoff reports none of your app's 404s from these servers. (Each domain can also turn 404 reports off in RedirHub.)
PORT_HEALTHoffA 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_PROTOCOLoffBehind 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_LISTEN127.0.0.1:18090Where 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_APIhttps://api.redirhub.comThe 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.

⁠Common setups

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:

⁠Your own config

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.

PathWhat it is
proxy.confHow a request reaches your app: proxy_pass, headers, timeouts. The image writes it from UPSTREAM; a file of yours replaces it whole.
http.d/*.confAdded to the http block: an upstream with several app servers, a map, a limit_req_zone.
server.d/*.confAdded 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.

⁠Redirects and 404s

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.

  • A link for a path answers before your app, even when the page exists, whatever the method (a password form posts to its link). Add one in RedirHub and the page is taken down or moved within seconds, without a release of your app.
  • A catch-all link (the bare domain, or a wildcard domain's) only takes your app's 404s for 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.
  • Your app's 404s are reported to RedirHub, where they show up in Analytics, unless you turn 404 reporting off for the domain, or 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.
  • Your app answers whenever a link cannot: a link that is paused, expired or banned, a domain that is not (or no longer) a verified self-hosted domain of your workspace, a copy that has not arrived yet, anything that goes wrong. The container never shows RedirHub's own "not found", "paused" or error pages on your domain.

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.

⁠How it works

  • The sync process registers the server with your token and keeps a local copy of your workspace's stream: its certificates, its self-hosted domains and the links of those domains. Changes are pushed to it within seconds; it also checks every 5 minutes.
  • OpenResty reads the start of each connection on 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.
  • For every other request on one of your self-hosted domains, OpenResty asks the redirector, which reads the same local copy, whether a link answers it: the link's answer goes to the visitor, everything else to 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.
  • Visits and 404s go back to RedirHub in batches, never delaying a request.
  • If RedirHub cannot be reached, the server keeps serving with the certificates and links it has; renewals happen well ahead of expiry.
  • Replacing the token in the dashboard stops every server still running the old one from syncing: run the new command on each of them.

⁠Updating

docker pull redirhub/edge
docker rm -f redirhub-edge
docker run ... (the same command, the same volume)
Tag summary
Recent tags
Content type
Image
Digest
sha256:8a210404b…
Size
185 MB
Last updated
9 days ago
docker pull redirhub/edge:latest