vfsoraki

vfsoraki

Phoenix generate https urls

I have a Phoenix 1.3 app that is running behind an Nginx reverse proxy, all in HTTP.

I wanted to migrate to HTTPS, so I got a certificate from Let’s Encrypt and changed Nginx config to do it. All worked fine.

I generate a bunch of urls inside my Phoenix app, using MyApp.Web.Router.Helpers.*, but they generate HTTP urls. So I channged my app config in prod.exs from url: [host: "my.host", port: 80] to url: [host: "my.host", port: 443]. But now the urls are being generated like http://my.host:443/path.

How can I tell Phoenix to stay on HTTP, but generate urls in HTTPS?

PS. If I was not clear, I don’t want my Nginx and Phoenix to talk over HTTPS, I just want Phoenix url helpers to generate HTTPS urls. I have already read Endpoint configuration, but I could not find something useful.

Marked As Solved

NobbZ

NobbZ

Documentation of Phoenix.Endpoint says

:url - configuration for generating URLs throughout the app. Accepts the :host, :scheme, :path and :port options.

So it should be enough to add scheme: "https" to your :url config

Also Liked

dimitarvp

dimitarvp

It’s scheme btw. Caught me off-guard for a sec so figured I should warn future readers.

Last Post!

dimitarvp

dimitarvp

As far as I can tell, it’s already edited to show scheme and not schema.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
mikehostetler
TL;DR; Best practices for shipping an ecosystem of connector packages to Hex in a responsible way? Background I have a project, jido_c...
New

We're in Beta

About us Mission Statement