Should Nginx be at the front of HAProxy or opposite?

If you plan to have every web server available over HTTPS, then you'll need to install Nginx in front of HAProxy. With that configuration, your Nginx will handle all the SSL work and send the decrypted HTTP traffic directly to the HAProxy frontend, which will then load-balance requests to your web servers based on the rules you specify.

The idea of using LVS, as mentioned by womble is that it's somewhat less intrusive since it doesn't hold a connection between your web server and the client accessing the site. On the other hand, LVS will only provide you with simple load-balancing and won't allow you to forward requests based on file extension, requested URL, headers, etc. That's why HAProxy is used in many situations.

If you only need SSL on one server (non load-balanced) then you're safe to use HAProxy for everything without using Nginx. On the other hand you'll have one issue with being unable to see the client's source IP address in the web server's HTTPS logs (because HAProxy rewrites that address). The IP will be in HAProxy logs if you enable it though ;)


haproxy since v. 1.5, released in 2014, does support SSL like a charm, including SNI.

Therefore I would put haproxy in front of nginx.


You should just use nginx, it does everything you need as a frontend webserver. If you need front-end load-balancing, use an L3 load balancer such as Linux Virtual Server, because it doesn't get in the way like HAproxy does. Use HAproxy if required to do behind-the-scenes load balancing, like balancing requests to a pool of backend workers.