Redirecting Phoenix app from HTTP -> HTTPS and www -> apex not working?

I’m trying to make it so that my app redirects:

  • www → apex

My app SSL config: ( doesn’t give you file access to your key/cert, so I’m not sure what to put in those, if I get rid of them things seem to work fine?)

My SSL cert is all good:

My secrets:

My fly.toml:

As for the redirection of www to the apex domain, I wrote this myself and it didn’t work. I then tried using GitHub - remi/plug_canonical_host: PlugCanonicalHost ensures that all requests are served by a single canonical host., but that doesn’t work either. I’m not sure if I’m doing something wrong or if is doing some automagical stuff in the background I’m not seeing.

Any ideas?

Fly terminates SSL at the proxy, so you should only need to configure:

force_ssl: [rewrite_on: [:x_forwarded_proto]]

For the canonical host, if you can share what you wrote, I could comment further, but a simple plug should do the job just fine :slight_smile:


Ah, so the Fly proxy handles all SSL? So should I get rid of all of the Phoenix-specific SSL/HTTPS config?

Once I do that, the HTTP → HTTPS part works, though the www redirect does not.

In config/prod.exs: (I made sure to use flyctl secrets set

in lib/nezteb_web/endpoint.ex:

UGH literally as I uploaded that last screenshot, I realize that I didn’t change the app name in the function:

:my_app # should have been :nezteb...
    |> Application.get_env(:canonical_host)

Now things seem to be working. Thanks Chris! :heart:

1 Like