32

What are the differences between HAProxy and Nginx when it comes to their abilities as a reverse proxy?

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
Quintin Par
  • 4,293
  • 10
  • 46
  • 72

4 Answers4

47

HAProxy is really just a load balancer/reverse proxy. Nginx is a Webserver that can also function as a reverse proxy.

Here are some differences:

HAProxy:

  • Does TCP as well as HTTP proxying (SSL added from 1.5-dev12)
  • More rate limiting options
  • The author answers questions here on Server Fault ;-)

Nginx:

  • Supports SSL directly
  • Is also a caching server

At Stack Overflow we mainly use HAProxy with nginx for SSL offloading so HAProxy is my recommendation.

rmalayter
  • 3,744
  • 19
  • 27
Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
15

2019 update:

They are both stable and mature products. HAProxy is dedicated to load balancing and is better at that, whereas nginx is a webserver that can act as a load balancer.

Both:

  • HTTPS support
  • Websocket support
  • Stable, mature and very efficient products
  • Can handle 10k connections with minimal or no tuning

HAProxy:

  • TCP, TCP-SSL, HTTP and HTTPS load balancing
  • More flexibility on health checks and failover conditions
  • Basic caching (v1.8 - 2017)
  • Customizable log format, to import access logs to kibana/splunk/graylog
  • Detailed status page, to see active requests and servers status
  • Exportable metrics, to integrate with monitoring solutions (graphite/prometheus/datadog)
  • More high-performance oriented. Better indicated to handle 100k connections or 40 GbE interfaces.

Nginx:

  • HTTP and HTTPS load balancing (TCP - UDP in paid edition)
  • More flexibility on caching
  • Customizable log format, to import access logs to kibana/splunk/graylog
  • No status page (paid edition only)
  • No exportable metrics (paid edition only)
  • Can serve local files
  • Can serve FastCGI applications (not CGI)

HAProxy is a free software, fully open source. They make money by selling hardware appliance with HAProxy pre-installed.

Nginx is open core and many features are only available in the paid edition. Notably, it's lacking a status page and monitoring metrics that is a big NO NO to operate a load balancer.

user5994461
  • 2,749
  • 1
  • 17
  • 30
11

I use nginx to frontend HAProxy, but only for SSL termination.

HAProxy is a much more tunable and manageable load balancer (in my experience).

I also incorporate Varnish for static object caching. (as a specific backend of HAProxy)

See this Server Fault question for more info. Ordering nginx/varnish/haproxy

Joel K
  • 5,765
  • 2
  • 29
  • 34
  • 3
    The newest (September 2012) unstable builds of HAProxy now support SSL. (potentially removing my need to run nginx) – Joel K Oct 01 '12 at 00:12
5

If needed only for load balancing HA proxy is better. But combining both nginix and HA proxy can be more useful, as nginix is fast in providing static content, it will serve all request for static data and then send all request to HA proxy which serve as load balancer and send request to web server to serve request by balancing load.

Mitesh
  • 51
  • 1
  • 1