basecamp / kamal-proxy

Lightweight proxy server for Kamal
https://kamal-deploy.org/
MIT License
754 stars 31 forks source link

Wild card domains #30

Closed simonhutchings closed 1 month ago

simonhutchings commented 2 months ago

Has anyone had any luck with wildcard domains?

simonhutchings commented 2 months ago

The strange thing is, the certificate seems to be ok, but not redirecting to the app.

proxy:
  ssl: true
  host: *.example.com
  app_port: 3000
  healthcheck:
    interval: 15
    path: /up
    timeout: 5

but if i use a full subdomain, it works

proxy:
  ssl: true
  host: subdomain.example.com
  app_port: 3000
  healthcheck:
    interval: 15
    path: /up
    timeout: 5

Wondering if it's anything to do with the load balancer on cloudflare, but was working fine with the traefik solution on kamal 1

anthonynsimon commented 2 months ago

AFAIK in order to issue wildcard certificates kamal-proxy needs to use the DNS challenge for let's encrypt.

Maybe relevant to this discussion too: https://github.com/basecamp/kamal-proxy/issues/26

aarroisi commented 1 month ago

I also need this functionality. It would be great if we can use wildcard, even without the auto SSL generation.

kevinmcconnell commented 1 month ago

Wildcard routing without SSL is something I think we can add soon. Then if you want to also handle SSL at the proxy, probably the easiest way will be to bring your own certs (once #17 lands).

Also, fwiw we do have limited wildcard support now: if you deploy an app without specifying a hostname, that app will get all the traffic that isn't explicitly routed to another app. In other words if you do this:

kamal-deploy app1 --target=host1
kamal-deploy app2 --target=host2 --host=app.example.com,api.example.com

...then app1 receives all the traffic that doesn't have a hostname of app.example.com or api.example.com. This doesn't allow having multiple apps deployed together that both use wildcard subdomains. But for certain setups it might cover what you need -- like if you have a single app, or if only one of your apps needs to handle wildcards.

aarroisi commented 1 month ago

That's awesome! Thanks for that.

Also, fwiw we do have limited wildcard support now: if you deploy an app without specifying a hostname, that app will get all the traffic that isn't explicitly routed to another app. In other words if you do this:

Yes, I'm aware of that and have been using it.

My use case is that in one server I need to handle:

to route to different apps. Currently, we need to make adjustment outside of Kamal to make that works, but if it can be handled all by Kamal that would be really great.

simonhutchings commented 1 month ago

This is how I’ve set it up for the moment, as no way of telling what the subdomain will be for tenants.On 1 Oct 2024, at 13:03, Kevin McConnell @.***> wrote: Wildcard routing without SSL is something I think we can add soon. Then if you want to also handle SSL at the proxy, probably the easiest way will be to bring your own certs (once #17 lands). Also, fwiw we do have limited wildcard support now: if you deploy an app without specifying a hostname, that app will get all the traffic that isn't explicitly routed to another app. In other words if you do this: kamal-deploy app1 --target=host1 kamal-deploy app2 --target=host2 --host=app.example.com,api.example.com

...then app1 receives all the traffic that doesn't have a hostname of app.example.com or api.example.com. This doesn't allow having multiple apps deployed together that both use wildcard subdomains. But for certain setups it might cover what you need -- like if you have a single app, or if only one of your apps needs to handle wildcards.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

kevinmcconnell commented 1 month ago

@simonhutchings @aarroisi I've just merged support for routing with wildcards. It will be available when we do the next Kamal release (which is likely to be quite soon).

You can see the details in #45, but the idea is that you can now specify hosts like *.example.com in order to have an app to receive requests for all subdomains of example.com, and so on.

aarroisi commented 1 month ago

@kevinmcconnell Thanks a lot for this! Can't wait to try it on Kamal.