https://3000-<id>.instabox.tech. To
serve the same app at https://app.example.com, run a reverse proxy on your domain and let it pass
requests to the port’s URL. Use this when a customer or a teammate should see your name in the
address bar, or when a webhook sender needs a fixed address that you control.
InstaBox does not host your domain or its certificate. You own the DNS record, the certificate, and
the proxy.
Before you start
- Publish the port and copy its URL. See Public and private ports.
- Point a DNS record for your domain at the host that runs your proxy.
- Have a certificate for your domain on that host. Caddy gets one by itself when the DNS record points at it.
Proxy a public port
The InstaBox proxy finds the port by theHost header, so your proxy must send the port’s own host
name as Host, not your domain. It must also connect over HTTPS on port 443, because the port’s URL
does not answer plain HTTP.
https://app.example.com. You see the same response as on the port’s own URL.
Proxy a private port
A private port answers only requests that carry its token. Publish the port with--private, take
the token from the link it prints (the part after ?_token=), and let your proxy send it in an
Authorization header. Your visitors then need no link, and whoever reaches the port’s own URL
without the token gets 401.
Keep the token out of the config file. This Caddyfile reads it from the environment variable
INSTABOX_PORT_TOKEN.
Caddyfile
proxy_set_header lines.
WebSockets
Caddy passes a WebSocket upgrade to the port without extra config. In nginx, theUpgrade and
Connection lines in the config above do it. The Authorization header that the proxy adds
applies to the upgrade request too, so a WebSocket to a private port needs nothing more.
nginx closes a WebSocket when the app sends nothing for 60 seconds. If your connections stay
silent for longer, raise the limit with proxy_read_timeout 1h; in the location block, or let
the app send a ping more often. Caddy does not close a silent WebSocket after 60 seconds.
Limits
Your app is two proxies away from the visitor, and the InstaBox proxy does not know your domain.-
Host headers. Your app sees
Host: 127.0.0.1:<port>, andX-Forwarded-Hostis the port’sinstabox.techname, not your domain. AnX-Forwarded-Hostthat your proxy sends is replaced. If the app needs your domain, send it in a header of your own and read that header in the app:header_up X-Original-Host {host}in Caddy,proxy_set_header X-Original-Host $host;in nginx. -
The visitor’s address.
X-Forwarded-Forholds the address of your proxy, not of the visitor, and anX-Forwarded-Forthat your proxy sends is replaced. To give the app the visitor’s address, send it in a header of your own:header_up X-Real-IP {remote_host}in Caddy,proxy_set_header X-Real-IP $remote_addr;in nginx. -
Redirects. A relative redirect, such as
Location: /login, works. An absolute redirect that the app builds from the host it sees, or a redirect tolocalhost:<port>, reaches your proxy with the port’sinstabox.techURL in it. nginx with the config above changes that URL back to your domain. Caddy passes it on, so the visitor leaves your domain. To change it in Caddy, add the line below insidereverse_proxy, or set the app’s public URL to your domain in its config.Caddyfile -
Cookies. The InstaBox proxy removes the
Domainattribute of every cookie the app sets and addsSecure. The browser therefore keeps the cookie for exactlyapp.example.com, not for its subdomains, and only over HTTPS. -
The visitor’s
Authorizationheader. The proxy’sAuthorizationline replaces a header that the visitor sends, so the app never sees the visitor’s own. Do not add the token as a secondAuthorizationfield: a request with two is refused with400. If your app readsAuthorizationitself, send the token in the cookie__Host-instabox_port_authinstead. The InstaBox proxy removes that cookie and passes the visitor’sAuthorizationheader and other cookies to the app. In Caddy, write this line in place of theAuthorizationline.In nginx, write this line in place of theCaddyfileAuthorizationline. -
Streaming in nginx. nginx holds a response back until its buffer fills or the response
ends, so server-sent events arrive late and together. Add
proxy_buffering off;to thelocationblock to pass each event on when the app sends it. Caddy needs no setting. - One port per route. A route in your proxy points at one published port. The port’s URL does not change, also when you unpublish the port and publish it again, but another port or another machine has another URL. A private port that you publish again gets a new token.
Troubleshooting
404 with a JSON body: route not found
404 with a JSON body: route not found
The request reached InstaBox with your domain as
Host. Send the port’s host name: header_up Host {upstream_hostport} in Caddy, proxy_set_header Host 3000-<id>.instabox.tech in nginx.404: This URL is not published.
404: This URL is not published.
The
Host header is right, but no port is published under that name. Compare the host name in
your proxy config with the output of instabox port ls, and publish the port again if you
unpublished it.The proxy cannot connect, or reports a certificate error
The proxy cannot connect, or reports a certificate error
Connect to the port’s host name over HTTPS on port 443. Plain HTTP on port 80 does not answer.
The certificate is for
*.instabox.tech, so a proxy that checks the certificate must check it
against the port’s host name and not against your domain.401: This URL is private.
401: This URL is private.
The proxy did not send the port’s token, or sent an old one. Check that the
Authorization
header is Bearer followed by the current token. After you rotate the token, update the proxy.502 or 503
502 or 503
502: nothing listens on the port in the machine. Start your server. 503: the machine is
paused by you, stopped, or still waking. A machine that paused itself wakes on the first
request. See Reach a paused machine.Public and private ports
Publish a port, make it private, and rotate its token.
Auto-pause and max-run
When a machine pauses itself and what wakes it.