dwyl / learn-phoenix

:fire: Phoenix is the web framework without compromise on speed, reliability or maintainability! Don't settle for less. :rocket:
650 stars 45 forks source link

How to force SSL/HTTPS on Phoenix Apps hosted on Heroku #122

Open RobStallion opened 5 years ago

RobStallion commented 5 years ago

Look into how to force a phoenix application to redirect to https if a user goes to a http endpoint.

Example of what we want to recreate...

RobStallion commented 5 years ago

To fix this we just have to add the following line to our config/prod.exs file.

  force_ssl: [rewrite_on: [:x_forwarded_proto]]

Example...

config :your_app, YourAppWeb.Endpoint,
  http: [:inet6, port: System.get_env("PORT") || 4000],
  url: [host: "example.com", port: 80],
  cache_static_manifest: "priv/static/cache_manifest.json",
  force_ssl: [rewrite_on: [:x_forwarded_proto]]