O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Protecting the Phoenix app with SSL

In a production scenario, it will be likely for a Phoenix application to listen to requests using a secure protocol. HTTPS will be used in detriment of plain HTTP.

To accept connections securely, we need to launch the application with SSL support.

Fortunately, in Phoenix, configuring SSL is quite simple.

Getting ready

In a Phoenix application, place the *.key and *.cert files under the priv directory.

How to do it…

To configure SSL in a Phoenix application, we will need to add the following to the config/prod.exs file:

config :phoenix, Todo.Router,
  https: [port: 443,
          host: "example.com",
          keyfile: System.get_env("YOUR_SSL_KEY_FILE"),
          certfile: System.get_env("YOUR_APP_SSL_CERT_FILE")],

How it works…

We insert the configuration ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required