# HTTPS SSL Phoenix 1.4

**URL:** <https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868>\
**Category:** Questions\
**Tags:** phoenix, ssl, https\
**Created:** [December 19, 2018, 7:18pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868 "2018-12-19T19:18:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Codball](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/codball/32/12944_2.png) [@Codball](https://forum.elixirforum.com/u/Codball)\
**Post date:** [December 19, 2018, 7:18pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/1 "2018-12-19T19:18:57Z")

</div>

Been trying to generate a self-signed certificate for HTTPS testing on a webserver hosted on an AWS EC2 instance. When I run MIX\_ENV=prod mix phx.server I get the error:

```
19:09:05.450 [error] Failed to start Ranch listener BlackbookWeb.Endpoint.HTTPS in 
:ranch_ssl:listen([cacerts: :..., key: :..., cert: :..., alpn_preferred_protocols: ["h2", "http/1.1"], 
next_protocols_advertised: ["h2", "http/1.1"], reuse_sessions: true, secure_renegotiate: true, certfile: 
'/home/ubuntu/documents/blackbook/_build/prod/lib/blackbook/priv/cert/selfsigned.pem', keyfile: 
'/home/ubuntu/documents/blackbook/_build/prod/lib/blackbook/priv/cert/selfsigned_key.pem', port: 443]) for 
reason :eacces (permission denied)

```

Did I generate the cert wrong with mix phx.gen.cert?  
When I try setting up Let’s Encrypt using `certbot certonly` it gives me a failed authorization procedure as well.

I’ve added `only: ~w(css fonts images js favicon.ico robots.txt .well-known)` to my endpoint.ex under Plug.Static.

My config looks like:

```
config :blackbook, BlackbookWeb.Endpoint,
  load_from_system_env: true,
  http: [port: 4000],
  server: true, 
  secret_key_base: Application.get_env(:blackbook, :secret_key_base),
  url: [host: "bb.bba.com", port: 443],
  cache_static_manifest: "priv/static/cache_manifest.json",
  https: [port: 443,
          otp_app: :blackbook,
          keyfile: Application.get_env(:blackbook, :keyfile),
          certfile: Application.get_env(:blackbook, :certfile)
          ],
  force_ssl: [hsts: true]

```

Having trouble finding my error. Do I need to tell my Ubuntu EC2 instance to listen on 443? My admin says he has forwarded the port already, though it’s possible he did it incorrectly.

---

<div class="post-metadata">

**Author:** ![alexgaribay](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/alexgaribay/32/5261_2.png) [@alexgaribay](https://forum.elixirforum.com/u/alexgaribay)\
**Post date:** [December 19, 2018, 8:14pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/2 "2018-12-19T20:14:29Z")

</div>

To me, that looks like the app doesn’t have permission to read the cert files.

---

<div class="post-metadata">

**Author:** ![Codball](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/codball/32/12944_2.png) [@Codball](https://forum.elixirforum.com/u/Codball)\
**Post date:** [December 19, 2018, 8:29pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/3 "2018-12-19T20:29:57Z")

</div>

how do I give it permission to read the cert files?

---

<div class="post-metadata">

**Author:** ![idi527](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/85e7bf/32.png) [@idi527](https://forum.elixirforum.com/u/idi527)\
**Post date:** [December 19, 2018, 8:30pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/4 "2018-12-19T20:30:59Z")

</div>

👋

With `chmod`, probably.

---

<div class="post-metadata">

**Author:** ![Codball](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/codball/32/12944_2.png) [@Codball](https://forum.elixirforum.com/u/Codball)\
**Post date:** [December 19, 2018, 8:36pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/5 "2018-12-19T20:36:10Z")

</div>

Do you have an example? Relatively new to Ubuntu.

---

<div class="post-metadata">

**Author:** ![yurko](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/yurko/32/2369_2.png) [@yurko](https://forum.elixirforum.com/u/yurko)\
**Post date:** [December 19, 2018, 8:43pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/6 "2018-12-19T20:43:49Z")

</div>

`whoami` under the same user that you run mix tasks will give you the username, then `sudo chown -R username:username /home/ubuntu/documents/blackbook` to make this user (and their group) own the project root and all dirs / files recusrsively

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [December 19, 2018, 9:06pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/7 "2018-12-19T21:06:20Z")

</div>

Standard users are usually not allowed to listen on ports lower than 1024. You need to use another port.

I do assume, that `/home/ubuntu/` is the homefolder of the user that you are using to run the application. And I therefore I usually assume that the certificates have proper permissions set.

---

<div class="post-metadata">

**Author:** ![Gazler](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gazler/32/1168_2.png) [@Gazler](https://forum.elixirforum.com/u/Gazler)\
**Post date:** [December 21, 2018, 8:04am UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/8 "2018-12-21T08:04:18Z")

</div>

There was recently a PR with a very detailed guide on this topic opened on Plug.

[https://github.com/elixir-plug/plug/pull/803](https://github.com/elixir-plug/plug/pull/803)

---

<div class="post-metadata">

**Author:** ![patrickdm](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/patrickdm/32/7579_2.png) [@patrickdm](https://forum.elixirforum.com/u/patrickdm)\
**Post date:** [June 11, 2019, 11:36pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/9 "2019-06-11T23:36:54Z")

</div>

> Standard users are usually not allowed to listen on ports lower than 1024

thanks @NobbZ, that was a good hint for me! (+ a note for my-future-self: check [What's the best way to serve restricted ports (e.g. 80, 443) with Phoenix?](https://forum.elixirforum.com/t/whats-the-best-way-to-serve-restricted-ports-e-g-80-443-with-phoenix/2841)

---

<div class="post-metadata">

**Author:** ![SZJX](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@SZJX](https://forum.elixirforum.com/u/SZJX)\
**Post date:** [September 9, 2024, 12:04pm UTC](https://forum.elixirforum.com/t/https-ssl-phoenix-1-4/18868/10 "2024-09-09T12:04:33Z")

</div>

For some reason the `chown` still didn’t work in my case. I had to start the server with sudo: `sudo MIX_ENV=prod mix phx.server`. It might have something to do with the way this particular server is configured.
