elixir-plug / plug_cowboy

Plug adapter for the Cowboy web server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use all Plug.SSL.configure/2 options

jjcarstens opened this issue · comments

The docs seem to state that you can pass any option from Plug.SSL.configure/1 (see this)

But in practice, that doesn't seem to work for me. I don't know enough about plug to know which rabbit hole to go down for this. Any help is appreciated.

iex)> opts = [
  certfile: "/path/to/my.crt",
  keyfile: "/path/to/my.key",
  host: "coolhost.dev",
  rewrite_on: [:x_forwarded_proto],
  port: 443
]

iex)> Plug.Cowboy.https MyApp.Router, [], opts
{:error,
 {{:shutdown, {:failed_to_start_child, :ranch_acceptors_sup, :badarg}},
  {:child, :undefined, {:ranch_listener_sup, MyApp.Router.HTTPS},
   {:ranch_listener_sup, :start_link,
    [
      MyApp.Router.HTTPS,
      :ranch_ssl,
      %{
        connection_type: :supervisor,
        max_connections: 16384,
        num_acceptors: 100,
        socket_opts: [
          next_protocols_advertised: ["h2", "http/1.1"],
          alpn_preferred_protocols: ["h2", "http/1.1"],
          reuse_sessions: true,
          secure_renegotiate: true,
          certfile: '/path/to/my.crt',
          keyfile: '/path/to/my.key',
          port: 443,
          host: "coolhost.dev",
          rewrite_on: [:x_forwarded_proto]
        ]
      },
      :cowboy_tls,
      %{
        connection_type: :supervisor,
        env: %{
          dispatch: [
            {:_, [],
             [{:_, [], Plug.Cowboy.Handler, {MyApp.Router, []}}]}
          ]
        },
        stream_handlers: [Plug.Cowboy.Stream]
      }
    ]}, :permanent, :infinity, :supervisor, [:ranch_listener_sup]}}}

Also fails when trying to use child_spec/1

iex)> spec = Plug.Cowboy.child_spec(plug: MyApp.Router, scheme: :https, options: opts)
iex)> DynamicSupervisor.start_child(MyApp.Supervisor, spec)
{:error, {:shutdown, {:failed_to_start_child, :ranch_acceptors_sup, :badarg}}}

The only options I can get to work are :certfile and :keyfile. This may be user-error and I might just need help understanding how to specify the SSL opts correctly?

Yeah, It is a documentation issue. It accepts the options of Plug.SSL.configure not the Plug.SSL options. And the options for Plug.SSL.configure are not listed anywhere. :D It should work if you remove the host and rewrite_on options.

I have improved the docs in Plug master, thanks!