cloudflare / cloudflared

Cloudflare Tunnel client (formerly Argo Tunnel)
https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide
Apache License 2.0
9.3k stars 827 forks source link

Rewrite or change rules? (Like in Nginx) #408

Open xxxcrow opened 3 years ago

xxxcrow commented 3 years ago

Is it possible to add something similar like from nginx:

 rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
 rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
 rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
 location ^~ /.well-known {
 location = /.well-known/carddav { return 301 /remote.php/dav/; }
 location = /.well-known/caldav  { return 301 /remote.php/dav/; }

I know that it's possible to transform rules in cloudflare dashboard but i want to know if there's any local cloudflared solution Or maybe headers changing?

nmldiegues commented 3 years ago

Hello @xxxcrow ,

There is no such thing in cloudflared. I would argue there is unlikely to ever be, for the reason that you mention: we already have a product that allows to do that for hostnames proxied through Cloudflare (and all Tunnel's hostnames are hosted there), so you can just leverage what already exists out of the box: https://blog.cloudflare.com/tag/transform-rules/

Is there a reason why that wouldn't work?

xxxcrow commented 3 years ago

@nmldiegues only two rules transformation are allowed per domain on free plan 😅 And also, I was just interested, because I can't find enough information about all the ingress rules, and I though there might be some 😄

christidis commented 1 year ago

What about services that, based on some naming conventions, they need to end up in a different backend service or maybe with a different httpHostHeader flag set like the following (simplified) examples.

    # wildcard ingress rule for all foo cpu services
    - hostname: foo-*-cpu.example.com
      service: http://foo-prod-*-cpu.main-foo-prod.svc.cluster.local:5000

    # proxy foo gpu services through Keda-http to scale down to zero
    - hostname: foo-*-gpu.example.com
      originRequest:
        httpHostHeader: foo-*-gpu-int.example.com
      service: http://keda-add-ons-http-interceptor-proxy.keda.svc.cluster.local:8080

There may be other usecases to manipulate hostname, subdomais, paths etc.

This is currently not supported.