Skip to main content
A published port has a URL on the InstaBox domain, such as 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 the Host 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.
Open https://app.example.com. You see the same response as on the port’s own URL.
A public port stays reachable at its instabox.tech URL too. Access rules on your proxy, such as a login or an IP allow list, do not protect that URL. To make your proxy the only way in, use a private port.

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
In nginx, add this line next to the other proxy_set_header lines.
The InstaBox proxy removes the token before it passes the request on, so your app does not see it.
Your proxy now holds the port’s token, and everyone who can reach your proxy can reach the app. Add your own sign-in on the proxy if the app needs one. When the token leaks, rotate it and give the proxy the new one. See Replace a private link.

WebSockets

Caddy passes a WebSocket upgrade to the port without extra config. In nginx, the Upgrade 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>, and X-Forwarded-Host is the port’s instabox.tech name, not your domain. An X-Forwarded-Host that 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-For holds the address of your proxy, not of the visitor, and an X-Forwarded-For that 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 to localhost:<port>, reaches your proxy with the port’s instabox.tech URL 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 inside reverse_proxy, or set the app’s public URL to your domain in its config.
    Caddyfile
  • Cookies. The InstaBox proxy removes the Domain attribute of every cookie the app sets and adds Secure. The browser therefore keeps the cookie for exactly app.example.com, not for its subdomains, and only over HTTPS.
  • The visitor’s Authorization header. The proxy’s Authorization line replaces a header that the visitor sends, so the app never sees the visitor’s own. Do not add the token as a second Authorization field: a request with two is refused with 400. If your app reads Authorization itself, send the token in the cookie __Host-instabox_port_auth instead. The InstaBox proxy removes that cookie and passes the visitor’s Authorization header and other cookies to the app. In Caddy, write this line in place of the Authorization line.
    Caddyfile
    In nginx, write this line in place of the Authorization line.
  • 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 the location block 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

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.
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.
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.
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: 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.