Multiple HTTPS sites on Gigalixir using master_proxy

I made a post before 1 Gigalixir instance hosting multiple HTTPS sites
but I am still not understanding how can I support https. The multi_proxy config was a little bit difficult, but I think as long as your endpoints do not specify a port and they let multi_proxy define the port, it works. But if you have https, I do not see what options are needed (or maybe, it isn’t needed?)

config :master_proxy,
  http: [port: 80],
  #  http: [port: String.to_integer(System.get_env("PORT", "4000"))],  # <--- is this better?
  #  https: [:inet6, port: 443],   # <--- this causes an error.  How to specify a local cert?
  backends: [
    %{
      host: ~r{^(www\.)?myapp\.com$},
      phoenix_endpoint: MyAppWeb.Endpoint
    },
  ]

If https is uncommented, it gets this error:

(ArgumentError) could not start Cowboy2 adapter, missing option :key/:keyfile

but I do not understand how to fix this in dev.

Also I do not understand whether master_proxy should be listening on port 4000 (the PORT), or if it should be listening on port 80.

Thank you sorry I am confused

I think the way Gigalixir works (and also Heroku, Render.com etc) is that they provide you the SSL layer for you, and in your own application you should only be concerned with HTTP layer, and maybe a redirect from HTTP to HTTPS.

So you set up your application the usual way, with listening only over HTTP on $PORT, then add custom domains in Gigalixir and set up redirect - all without changing anything in your code, but rather by altering the Gigalixir configuration with it’s CLI:

https://gigalixir.readthedocs.io/en/latest/domain.html#how-to-set-up-ssl-tls

2 Likes