Phoenix generate https urls

I have a Phoenix 1.3 app that is running behind an Nginx reverse proxy, all in HTTP.

I wanted to migrate to HTTPS, so I got a certificate from Let’s Encrypt and changed Nginx config to do it. All worked fine.

I generate a bunch of urls inside my Phoenix app, using MyApp.Web.Router.Helpers.*, but they generate HTTP urls. So I channged my app config in prod.exs from url: [host: "my.host", port: 80] to url: [host: "my.host", port: 443]. But now the urls are being generated like http://my.host:443/path.

How can I tell Phoenix to stay on HTTP, but generate urls in HTTPS?

PS. If I was not clear, I don’t want my Nginx and Phoenix to talk over HTTPS, I just want Phoenix url helpers to generate HTTPS urls. I have already read Endpoint configuration, but I could not find something useful.

Documentation of Phoenix.Endpoint says

:url - configuration for generating URLs throughout the app. Accepts the :host, :scheme, :path and :port options.

So it should be enough to add scheme: "https" to your :url config

9 Likes

I really really have no idea how could I miss that!

Thanks mate.

It’s scheme btw. Caught me off-guard for a sec so figured I should warn future readers.

4 Likes

Thanks for pointing this out. I blindly copied @nobbZ’s suggestion and it didn’t work.

@NobbZ Can you please edit it?