# Phoenix http health checks

**URL:** <https://community.fly.io/t/phoenix-http-health-checks/2894>\
**Category:** General\
**Created:** [October 21, 2021, 10:32am UTC](https://community.fly.io/t/phoenix-http-health-checks/2894 "2021-10-21T10:32:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yannis](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/yannis/32/48284_2.png) [@yannis](https://community.fly.io/u/yannis)\
**Post date:** [October 21, 2021, 10:32am UTC](https://community.fly.io/t/phoenix-http-health-checks/2894/1 "2021-10-21T10:32:08Z")

</div>

I have a Phoenix app that uses the [fly.io](http://fly.io) tls middleware.

My endpoint is configured to redirect http requests to https with :

```auto
force_ssl: [rewrite_on: [:x_forwarded_proto]

```

This means that every http health checks (`http://localhost:8080/healthz`) are being redirected to `https://[public_domain_name]/healthz`.

How can we fix this?

---

<div class="post-metadata">

**Author:** ![andykent](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/andykent/32/51014_2.png) [@andykent](https://community.fly.io/u/andykent)\
**Post date:** [October 21, 2021, 10:56am UTC](https://community.fly.io/t/phoenix-http-health-checks/2894/2 "2021-10-21T10:56:54Z")

</div>

What we do in this situation is move the health check logic into a plug and inject it before `Plug.SSL`

In our Endpoint we have something like (note order is important)

```auto
...

plug FooWeb.Plugs.HeathCheck

plug Plug.SSL,
    rewrite_on: [:x_forwarded_proto],
    exclude: ["localhost"]

...

```

Where a simple `HealthCheck` plug looks something like…

```auto
defmodule FooWeb.Plugs.HeathCheck do
  @behaviour Plug

  import Plug.Conn

  def init(opts), do: opts

  def call(%{request_path: "/_healthy"} = conn, _) do
    serve_pass!(conn, "HEALTHY")
  end

  def call(%{request_path: "/_ready"} = conn, _) do
    serve_pass!(conn, "READY")
  end

  def call(conn, _), do: conn

  def serve_pass!(conn, msg) do
    conn |> send_resp(200, msg) |> halt()
  end
end

```

This also gives you a nice place to check other health related things.

Hope that helps.
