hudsonbay
Is it a common practice to put a load balancer like Nginx or HAProxy in front of different Phoenix Nodes?
My question is because maybe a single Phoenix web server is capable of handling even more open TCP connections than a single reverse proxy in front of them, because maybe the reverse proxy will go down before the Phoenix web server does. I’m even assuming I have a failover technique for the cluster of reverse proxies.
Also my question is, which is the recommended way to horizontally scale phoenix web servers?
Definitely this is a question from a newbie ![]()
Thanks in advance
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
pablodavila
From what I’ve heard most people do set up a reverse proxy in front of Phoenix. I haven’t had to run a Phoenix server in production but I’ve used nginx in front of other servers with no issues and would probably do it with Phoenix.
I think it’s generally easier to manage SSL and configuration this way; I don’t think you’ll run into performance issues. That’s my 2 cents anyway.
bobek
It really depends on your deployment architecture.You would typically use some sort proxy as a load-balancer to send traffic to more then one application server. That would simplify your deployments, as it is easier to drain nodes.
You would also handle ssl certs on the front-end nodes. Configure all your cypher suites and such.
If you have microservices, you may also push additional functionality into the front-end layer. For example authentication. Your services may then trust headers as they would be injected by the front-end machine and not user directly.
Andrei
Hi there
I’ve used a plethora of web servers and proxies/loadbalancers over the years. It all depends on your needs. If you’re a single developer like me, you want the best energy conservation to productivity ratio.
If you have only one site on a VPS then yes, run Phoenix directly!
If you have multiple Phoenix apps and multiple sites then you need something to do load balancing and redirect requests from your 80/443 ports to your apps.
Here i’ve worked with many others and I’d recommend HAproxy, which I’m currently using to handle requests to a variety of apps including Phoenix apps.
Haproxy scales as long as you
However, even now as we’re speaking I’m searching a way to use cowboy (or another erlang/elixir land app) for the reverse proxy stuff. I want simplicity and energy/productivity conservation because each app you add-> complexity. I was able to find GitHub - heroku/vegur: Vegur: HTTP Proxy Library · GitHub. However it hasn’t been updated in some time and I’m not sure it has the latest HTTP/2 support.
I got GitHub - tallarium/reverse_proxy_plug: 🔛 an Elixir reverse proxy Plug with HTTP/2, chunked transfer and path proxying support · GitHub working perfectly with just ONE LINE of code. However it doesn’t support websockets out of the box.
And this is a bummer.
Scaling will depend on other things aswell, your database will be the hardest hit so you’ll have to decide which databases you’ll want to use and scale that before you’ll have worries about Phoenix.
Good luck
hudsonbay
Oh, thank you @Andrei . Great explanation. I love HAProxy and it can support websockets
Great explanation
konstantine
I asked a similar question on this forum not long ago. Having enjoyed the benefits of a Caddy 2 server in front of Phoenix, I would now go as far as saying that it was a no-brainer. Here’s an updated list of the things Caddy 2 helped me achieve (I presume that most would likewise apply to HAProxy):
• adding support for the latest protocols, such as TLS 1.3 or HTTP/3 (experimental)
• serving a maintenance page when the Cowboy / Phoenix web server is down
• adding security and other headers to all requests, or to a broad range of requests
• adding an authentication token header, e.g. to protect a staging server
• redirecting automatically from the domain root to the www subdomain
• dealing with the issue of trailing slashes in URL paths
• hosting static websites on the reverse proxy server itself
• serving multiple domains / subdomains that share a single IP address
axelson
You might be interested in a combination of:
Those two libraries are what I use to serve two Phoenix applications:
Without those applications being aware that they’re behind a proxy. And it’s actually all running on nerves via GitHub - nerves-project/nerves_system_vultr: Experimental - join the Nerves discord if interested · GitHub (although that is experimental)
Andrei
I’m a little confused by your statement
By looking at the code of master_proxy it seems to only work if everything is in the same app. There is NO (reverse) proxy forwarding going on on tcp or bsd socket.
When you say you have 2 phoenix applications, do you mean an umbrella or in the same app as in same Elixir mix/release? In my mind “2 applications” means 2 separate things:)
Plus those are missing on the fly configuration capabilities which are what makes Elixir/Erlang.. amazing. (And it’s darn difficult to get right with haproxy I have to admint)
The only app I found to do this was reverse_proxy_plug however it doesn’t work for websockets. So I had to experiment with other web servers including caddy to see if they can fit into the haproxy need. From what I see, caddy does a LOT of autoconfiguration and it seems allright, however, performance wise I’m not so sure.
I played with nerves before.
Is the nerves project for the VPS allright when it needs NIF’s which are recompiled (ugprades etc)?
axelson
Sorry, yes you are correct in your assessment of master_proxy. I read these posts too hastily and misunderstood the intention. The approach I mentioned is something you could do when you want to run multiple phoenix applications on a single VPS from a single BEAM instance, and is in no way a replacement for a general reverse proxy.
I’m not aware of a reverse proxy type library besides Vegur (which you’ve already looked at).