Book Image

Elixir Cookbook

By : Paulo Pereira
Book Image

Elixir Cookbook

By: Paulo Pereira

Overview of this book

Table of Contents (16 chapters)
Elixir Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 for HTTPS connections by defining the values of the port where the application will listen (443 is the default HTTPS port), the name of the host (the host for which the certificate files were generated), and...