Skip to main content In which situation I should use nginx vs haproxy : r/linuxadmin
Go to linuxadmin

In which situation I should use nginx vs haproxy

Both LB are best but I’m looking for differences between Ngnix and haproxy, what factors decide I should use either one?

All I know ngnix can handle layer 7 stuff better compare to haproxy which can handle layer 4 better.

Your RMM tools can't secure BIOS firmware. Discover how FirmGuard bridges the gap enabling you to remotely secure, configure & update BIOS firmware.
Thumbnail image: Your RMM tools can't secure BIOS firmware. Discover how FirmGuard bridges the gap enabling you to remotely secure, configure & update BIOS firmware.
Sort by:
Best
Open comment sort options
[deleted]

HAProxy is very powerful. I use it on a number of important sites and I’m always finding more features I can take advantage of.

I suggest you take a look at the configuration manual.

Compile it against OpenSSL 1.1.1 branch and you even have TLSv1.3 support.

Nginx is not a load-balancer, it's a web server that can act as a proxy and/or a load balancer. It's not completely compliant as a HTTP/1.1 proxy and some features are paywalled behind Nginx+ subscription, which is not cheap. But you can easily route requests based on URI and not just Host.

I have little experience with HAproxy, but from what I understand, it's features are more oriented to balancing requests to a number of instances of the same app. It's either impossible or hard to to modify a request, you can't route one URI to one group of servers and other URI to other group and so on.

If you need load balancing and you are running a number of instances of your app, I'd recommend using HAproxy.

If you need to load-balance routes, you should take a look at Nginx.

Disclosure: I work for HAProxy Technologies. You may be interested to know that HAProxy can route by URI, headers, cookies, etc. It can also modify the headers and path. It can send one request to one pool of servers and another to a different pool based on a condition you configure. Hope this helps.

More replies
More replies

Disclosure: I work for HAProxy Technologies. What makes you say that NGINX is better at Layer 7? When researching it, was there something specific you saw that it can not do? HAProxy has very strong L7 capabilities.

I don’t have direct experience with anyone of them because I’m using F5 for everything but recently app team in company started using ngnix because we can’t deploy F5 outside our datacenter in public cloud, they are using it for socket stream and they said only ngnix support that. But they stuck when ngnix doesn’t support weight base load-balancing, they wanted active standby solution not round robin, they decided using HAProxy because it handle active standby and weight.

More replies

If your webserver is Nginx than you may want to use Nginx as load balancer ... other than that stick with haproxy.

I'd love to hear people's thoughts and experiences with varnish compared to nginx and HAproxy.

My rule of thumb is that HAProxy is better as a network edge load balancer, and nginx is better as an app server (PHP-FPM, uWSGI, htaccess/ldaps/etc, static files, etc).

Both are fine products, and both can do (almost) all of the above - but I usually end up using both in concert, simply because each has different strengths.

When I google Load-Balancing then I always come to nginx and how to setup a reverse proxy. When it is so wrong? Why it's on google always on top?

Edited

“Load balancing” is a broad search term and I’m sure lots of companies (F5, Kemp, Avi Networks - which is now a part of VMWare) compete to get their content on the first page. NGINX has done a great job at blogging and getting the word out about itself. I’d expect that to continue now that it’s been acquired by F5. However, with that said, there are features that NGINX does not offer in its free product, including active health checks, proper logging and metrics, end to end HTTP/2, sticky sessions, DNS service discovery, proper if/unless/and/or operators, or a good dashboard. These are things included with HAProxy. Both offer a commercial version. The paid NGINX Plus is where you’ll find the bulk of the LB features. The paid HAProxy Enterprise adds security and admin modules.

More replies
More replies