HTTPS redirect with fly.toml

With a configuration file like:

....
[[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443
....

What is the best way to redirect all HTTP traffic to HTTPS? Should I use the TLS handler to handle port 80 traffic?

There’s no way to currently do that with just a fly.toml.

No, this will break a lot of things for your users.

You should add logic in your app to look for the X-Forwarded-Ssl header. If the value is on, it means we’ve handshook TLS, if off, then we didn’t. In the case of off, you can redirect the user to the same URL but with https://.

2 Likes

I’m using caddy as a reverse proxy in front of a couple private apps with each corresponding to a subdomain. I will have to find a way to implement that in caddy.

There might be more useful documentation / information when using X-Forwarded-Proto. My bad for recommending a less-standard header before.

I’m pretty sure Caddy must have something built-in to deal with this.

I found a solution. So I might as well share it here in hope that it helps someone else in the future, This: Redirecting HTTP to HTTPS when " auto_https off" is set - #2 by Mohammed90 - Help - Caddy Community