Reverse Proxy & TURN
Traffic in the other direction. Reverse proxy puts Ocalt in front of a server you own somewhere else - your hostname, Ocalt’s certificate, your machine serving. TURN mints relay credentials for peers who cannot reach each other directly.
Reverse Proxy
Point a hostname at Ocalt with DOMAIN, then hand Ocalt an origin to forward to. Ocalt terminates TLS, so the certificate is handled for you and your origin never needs one.
DOMAIN "app.tld.com" TO "mysite.ocalt.site" SET ?d
AFTER NEW REVERSE PROXY "app.tld.com" TO "https://203.0.113.9:8443" SET ?rp
AFTER EMIT ?rp("status")
AFTER EMIT ?rp("id")
(* https://app.tld.com now serves from your box, with Ocalt's certificate *)
DIRECTIVE "home-nas" TUNNEL PORT 3000 SET ?tunnel
AFTER NEW REVERSE PROXY "app.tld.com" TO ?tunnel("url") SET ?rp
(* A machine with no public address, on your own domain *)
REVERSE PROXY ?rp CACHE 3600 SECONDS
AFTER REVERSE PROXY ?rp FORWARD HEADER "X-Real-IP"
AFTER REVERSE PROXY ?rp FORWARD HEADER "X-Forwarded-Proto"
AFTER REVERSE PROXY ?rp TIMEOUT 30 SECONDS
REVERSE PROXY LIST SET ?all
AFTER FOREACH ?all SET ?p
OPEN
EMIT ?p("host") & " -> " & ?p("origin") & " (" & ?p("status") & ")"
CLOSE
AFTER REVERSE PROXY REMOVE ?rp("id")
DOMAIN - that is the proof of ownership. An unverified hostname is refused.What Each Setting Does
CACHE n SECONDS keeps a copy of each answer at Ocalt for n seconds, up to a day. Only answers that are safe to share are kept: a GET request with no cookie and no Authorization header, answered with status 200, with no Set-Cookie and nothing marked private or no-store. Anything else always goes to your origin. A copy served from the cache carries X-Ocalt-Cache: HIT, and still costs its query.
FORWARD HEADER "name" adds a header your origin should see. Four are filled in by Ocalt: X-Real-IP and X-Forwarded-For carry the visitor's address, X-Forwarded-Proto says https, and X-Forwarded-Host carries your hostname. Any other name passes the visitor's own header through. Everything else a browser sends (cookies, Authorization, the request body) goes to the origin anyway.
TIMEOUT n SECONDS is how long Ocalt waits for your origin, from 1 to 300 seconds; the default is 60. TO "origin" moves the proxy to another origin without removing it. Each statement changes one setting and returns the whole proxy, so ?rp("cache_seconds"), ?rp("timeout_seconds") and ?rp("forward_headers") always show where it stands. REVERSE PROXY takes the object NEW REVERSE PROXY returned, its id, or the hostname.
The origin must be on the public internet, or be Ocalt content such as a tunnel. A private address is refused: a machine with no public address is reached through a tunnel, as in the second example.
TURN
Two browsers behind restrictive networks often cannot reach each other, however correct the signalling. A TURN server relays the media between them. NEW TURN mints credentials for one.
NEW TURN SET ?turn
AFTER EMIT ?turn("urls")
AFTER EMIT ?turn("username")
AFTER EMIT ?turn("credential")
AFTER EMIT ?turn("expires")
NEW TURN SET ?turn
AFTER CAST ?turn AS JSON SET ?ice
AFTER HTML "script" TEXT `const ICE = ` & ?ice & `;
const pc = new RTCPeerConnection({ iceServers: [{
urls: ICE.urls, username: ICE.username, credential: ICE.credential
}]});`
NEW TURN VALID 4 HOURS SET ?turn
AFTER NEW TURN VALID 60 SECONDS SET ?shortlived
(* Default is 1 hour. Maximum is 24 hours. *)
The relay is at turn.ocalt.com. A credential is valid for an hour by default; the shortest is ten seconds and the longest is a day.
Full Verb Reference
| Verb | Description |
|---|---|
NEW REVERSE PROXY "host" TO "origin" SET ?rp | Front an origin you own, with automatic TLS |
REVERSE PROXY ?rp CACHE n SECONDS | Cache responses at the edge |
REVERSE PROXY ?rp FORWARD HEADER "name" | Pass a header through to the origin |
REVERSE PROXY ?rp TIMEOUT n SECONDS | How long to wait on the origin |
REVERSE PROXY LIST SET ?all / REMOVE "id" | List or tear down |
NEW TURN [VALID n HOURS] SET ?turn | Short-lived relay credentials - urls, username, credential, expires |