Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAProxy vs. Nginx

I was looking at using HAProxy and Nginx for load balancing, and I had some questions:

  • Should I use JUST HAProxy over Nginx for the proxy server?
  • Is there any reason to have HAProxy and Nginx installed on the same proxy server?

Thanks

like image 597
Pat841 Avatar asked Jan 16 '14 21:01

Pat841


People also ask

Which is better HAProxy or NGINX?

The major benefit of Nginx is that it can be used for many other things including serving static files or running dynamic apps. On the other hand, if you don't need a web server and would rather a load balancer that provides much more information by default then HAProxy might be the right choice.

Is HAProxy based on NGINX?

The system under test – HAProxy or NGINX – acted as a reverse proxy, establishing encrypted connections with the clients simulated by wrk threads, forwarding requests to a backend web server running NGINX Plus R22, and returning the response generated by the web server (a file) to the client.

What is better than HAProxy?

Envoy came out as the overall winner in this benchmark. It had the highest throughput in terms of requests per second. It's interesting that Envoy's throughput was several times higher than others. While HAProxy narrowly beat it for lowest latency in HTTP, Envoy tied with it for HTTPS latency.

Is there anything better than NGINX?

HAProxy, lighttpd, Traefik, Caddy, and Envoy are the most popular alternatives and competitors to NGINX.


1 Answers

haproxy is a "load balancer" it doesn't know to serve files or dynamic content. nginx is a web server capable of many interesting things. if you only need to load balance + HA some third web server then haproxy is enough. if you need to implement some static content or some logic in routing of the requests before terminating them on a third server then you may need nginx.

The reason you can see haproxy+nginx on the same host is that it allows you to bring down single nginx instances while haproxy continues to serve requests from other hosts. Imagine having a RR DNS using A records:

myapp.com IN A 1.1.1.1 myapp.com IN A 1.1.1.2 

where 1.1.1.1 and 1.1.1.2 are two hosts with haproxy+nginx configured to load balance between them. Now for some reason your 1.1.1.1's nginx goes down. The browsers that come to 1.1.1.1 are still being served by haproxy on it which in turn gets data from 1.1.1.2's nginx.

hope it helps

like image 142
Michael Tabolsky Avatar answered Sep 23 '22 05:09

Michael Tabolsky