PhoenixアプリにSSLでアクセスするための設定メモです。
ssl証明書を配置
どこに置いても特に問題ないですが、公式に乗っかってprivの下においてみます。
いちおうsslディレクトリ切って。
~/tutorial/priv/ssl/ --- server.key
|- server.crt
configを修正
環境に合わせてconfig.exsなりを修正。
今回は一旦dev.exsでやります
dev.exs
config :tutorial, Tutorial.Endpoint,
http: [port: 4000],
https: [port: 4433, # ←追加(443使ってたので4433で)
keyfile: Path.expand("priv/ssl/server.key"), # ←追加(相対パスで書く)
certfile: Path.expand("priv/ssl/server.crt")], # ←追加
# 省略
起動
サーバーを起動してみます。
$ mix phoenix.server
[info] Running ChildRearingQuestion.Endpoint with Cowboy using https on port 4433
[info] Running ChildRearingQuestion.Endpoint with Cowboy using http on port 4000
正常に起動した様子。
これでhttpsを4433で待つようになりました!