I am currently having an issue with what I think is the fly proxy.
I am trying to run a Caddy server in order to provide automatic ssl for my client domain names. For the context this is my Caddyfile sigle-proxy/Caddyfile at main · pradel/sigle-proxy · GitHub. What I want is to have any domain being able to add a CNAME pointing to alias.sigle.io (during my tests I am using test.leopradel.com) and then the Caddy server will generate a new ssl certificate if needed and reverse proxy the request to another application running on app.sigle.io.
I tried to deploy the exact same Caddyfile on a fresh DO droplet and everything is working fine, my ssl certificates are properly generated and the page is loaded.
But when I deploy the same configuration on Fly when I try to access test.leopradel.com it looks like my caddy server is not even reached and the request is stopped with “ERR_CONNECTION_CLOSED”. My guess is that my request is actually never calling my application but stopped somewhere before by your proxy?
If you’re using the tls handler, then we will close connections for which we don’t have a certificate because we can’t handshake. The hostname test.leopradel.com is not associated with your app, so we can’t generate a TLS certificate.
It looks like what you’re trying to do is let your server handle TLS handshakes. You’ll need to remove both tls and http handlers from your service ports. That will make our proxy pass-through TCP directly to your app.
Your fly.toml should look like:
[[services]]
internal_port = 8080 # port Caddy exposes
protocol = "tcp"
[[services.ports]]
port = "80"
[[services.ports]]
port = "443"
It’s worth noting that if you require the “real” remote address from clients, you will need to accept the haproxy protocol and use the proxy_proto handler for your ports.
I did a lot of tries with the config you suggested (so removing the handlers) and I feel like my server is actually never called. I changed my caddy file to log any incoming request, but the logs are not showing anything when I make the request (just from the health check).
$ curl http://test.leopradel.com/health
Im healthy!
I just noticed that you probably need 2 services. Both “external” ports 80 and 443 will hit your internal port 80. Looking at your config, you probably want 2 services, mapped respectively 80:80 and 443:443.
Oh btw, we can handle certificates for you if you add every hostname you need one for via flyctl or our graphql API (currently undocumented, but I can help you get setup).
Unless there’s a specific reason you want to generate them yourself. We’re delighted that it works for you!
I decided to go with this approach because usually, platforms allowing you to add custom domains have a hard limit at max 50 domain names per app (I think it’s an AWS limitation). So I decided to create my own reverse proxy as I would need more than 50.
I am definitely not opposed using your API, but would it be possible for my users to point a CNAME record to alias.sigle.io? From my understanding, they would have to point the record to “something.fly.io” right?
We’ll flatten CNAMEs another level, so it should work if you have customers point to your name that goes back to us. We have a few other customers doing this but I don’t remember the specifics, @Jerome anything special we need to do to make that work?
Just to add one more good reason to use us for TLS handshakes:
If you’re handshaking TLS from your app, you won’t benefit from the faster handshakes we’re able to do from our edge locations. We’ll have to proxy packets back and forth between your app and our edge to handshake TLS.
That’s indeed an interesting part and less maintenance for my app which is always great
Just two small questions then, can you confirm that you don’t have a limit in the number of custom domains I can add? (I saw that it’s 0.10$ per custom domain per month, which is totally fine)
There is no limit on the number of hostnames / certificates.
Yes, you can point alias.sigle.io A and AAAA records to your IPv4 and IPv6 for your app and tell your users to CNAME their hostnames to alias.sigle.io. We check for IPv6! CNAMEing alias.sigle.io to yourapp.fly.dev would also work if your DNS provider does proper flattening including IPv6.