Inlets Reverse Proxy with Caddy2

·

2 min read

If you read my past article, maybe you didn't notice if I use version 1 of caddy. While it's okay and running fine, I found that caddy 1 actually will be ended at October 2020, so migrate to caddy 2 is urged. The problem, caddy 2 is not backward compatible, so very likely I'll take a lot of time configuring this and that. Luckily, my configuration is very simple. I just use caddy to serve inlets.

I actually setup a new GCP compute engine to try the caddy and inlets. So, here is the Caddyfile:

mainsite.com {
root /var/www/html
}

nn.mainsite.com 
proxy / 127.0.0.1:8000 {
        transparent
}

proxy /tunnel 127.0.0.1:8000 {
        transparent
        websocket
}

With the new caddy 2, this is the adjustment I found to be working:

mainsite.com {
  respond / "Hi stranger!"
}

nn.mainsite.com {
  reverse_proxy 127.0.0.1:8000 
  reverse_proxy /tunnel {
    to 127.0.0.1:8000
    header_up Host {http.reverse_proxy.upstream.host}
    header_up X-Real-IP {http.request.remote_host}
    header_up X-Forwarded-For {http.request.remote_host}
    header_up X-Forwarded-Port {http.request.port}
    header_up X-Forwarded-Proto {http.request.scheme}
  }
  @websockets {
    header Connection *Upgrade*
    header Upgrade webscoket
  }
}

My next experiment will be dynamic subdomain for inlets client, so it will be almost the same with ngrok and serveo capability, though I'm not sure, since my DNS provider doesn't allow the wildcard subdomain.