Do I need Nginx for Web Phoenix Framework production?

Dear all,

I am still confuse to deploy my all phoenix apps into VPS production, do I need Nginx or just need the Erlang VM to handle traffic and so on?

I am preparing 1 VPS production for deploying my 10 app made with phoenix Framework each of it, but still confuse how to manage it all App into 1 single VPS,

For example 1 app for my main domain then the other 9 app is into subdomain

You can use just cowboy to do that (see GitHub - wojtekmach/acme_bank: An example ☂ project), but at least the “route per domain to separate apps” part is usually handled better by dedicated tools like nginx or caddy. I found caddy to be even simpler for that case, as it requires less explicit configuration for common requirements.

2 Likes

I deploy with docker and use Traefik on front. Traefik is the Nginx for containers. Traefik handles Letencrypt certificates generation and renewal on the fly and routes any new app you add with a subdomain without you need to change its configuration, instead you just add some Traefik labels to the docker.compose.yml file of your app.

I have published two repos at work to auto-setup Traefik from scratch in a new Debian server or EC2 instance:

The repos are based on a simplification of my personal setup I use for my production apps.

3 Likes

We use Cowboy in exactly the same way as acme_bank with a plug that match a specific host and redirects to the corresponding endpoint.

Our apps are all parts of single umbrella project. We manage six apps this way.

defmodule Proxy.Plug do
  def init(options) do
    options
  end

  def call(conn, _opts) do
    cond do
      conn.host =~ ~r{^subdomain.*} ->
        MyOtherApp.Endpoint.call(conn, [])
      true ->
        MyApp.Endpoint.call(conn, [])
    end
  end
end
3 Likes

Here is the proxy code we’re using:

3 Likes