77

If you have 5 web servers behind a load balancer (such as haproxy) and they are serving up content for the same domain, do you need SSL certificates for all the servers, or can you use the same certificate on each server?

I know you can put all SSL requests on a specific server, but that requires distributed session info and hoping it doesn't come to that.

Derek Gathright
  • 881
  • 1
  • 7
  • 5

5 Answers5

77

If you have 5 web servers behind a load balancer (...) do you need SSL certificates for all the servers,

It depends.

If you do your load balancing on the TCP or IP layer (OSI layer 4/3, a.k.a L4, L3), then yes, all HTTP servers will need to have the SSL certificate installed.

If you load balance on the HTTPS layer (L7), then you'd commonly install the certificate on the load balancer alone, and use plain un-encrypted HTTP over the local network between the load balancer and the webservers (for best performance on the web servers).

If you have a large installation, then you may be doing Internet -> L3 load balancing -> layer of L7 SSL concentrators -> load balancers -> layer of L7 HTTP application servers...

Willy Tarreau, the author of HAProxy, has a really nice overview of the canonical ways of load balancing HTTP/HTTPS.

If you install a certificate on each server, then be sure to get a certificate that supports this. Normally certificates can be installed on multiple servers, as long as the servers all serve traffic for one Fully Qualified Domain Name only. But verify what you're buying, certificate issuers can have a confusing product portfolio...

  • 3
    You can purchase certificates with Subject Alternative Names from many issuers now. The SAN field allows a certificate that is valid for multiple FQDNs. WARNING... There can be some issues with older web clients (IE6!), in some instances the client will not read the SAN attribute if the Subject attribute has an invalid FQDN. – Ryan Fisher Mar 24 '11 at 17:24
  • 4
    Plus 1 for linking to that excellent article by Willy Tarreau. – Nathan Hartley Oct 20 '11 at 19:21
  • 1
    In medium to large installations, doing the SSL offloading at the Big IP or other load-balancer (second option listed above) has the advantages of being faster, more scalable, less complicated (generally one certificate on LB) and less expensive from the certificate licensing side (multi-domain and SAN certs get pricey). – Darrell Teague Oct 08 '13 at 18:46
  • Hi @JesperM, for this flow `Internet -> L3 load balancing -> layer of L7 SSL concentrators -> load balancers`, is multiple load balancers needed, or only 1 instance is enough to do the job? – jumping_monkey Apr 02 '20 at 02:17
17

You should be able to use the same certificate on each server. If your web site is www.gathright.com, you should be able to buy a cert for that FQDN. Then you install it on each of your 5 servers behind the balancer.

Alternatively, you can get a separate cert for each web server, but include 'www.gathright.com' as a "Subject Alternative Name", which means each of the 5 certs would be valid for SSL to that general FQDN as well as SSL to the specific server FQDNs.

Ryan Fisher
  • 2,218
  • 16
  • 13
  • 8
    To clarify this response, you will install the cert on the server which generated the request. You would then export the cert from that server along with private key in order to import it on the other servers. – Charles Sep 25 '09 at 18:44
  • D'oh! Yeah, I forgot to mention that you need to export the private key. Thanks, Charles. – Ryan Fisher Mar 24 '11 at 17:20
  • But if I use SAN certs on each server, do they each need the same private key? – anschoewe Jun 28 '16 at 00:37
  • @anschoewe, no. They would each have their own private key and you'd have to pay x5 the price if you have 5 computers. – Alexis Wilke Sep 16 '16 at 18:35
  • 1
    @AlexisWilke - not sure what that means: if they use a SAN cert, they only need one cert, and therefore one key, and therefore 1 price. SAN certs can be used on multiple servers to serve one or more domains; the price goes up when adding *domains*, not when adding *servers* – dwanderson Jun 28 '18 at 22:23
  • @dwanderson Things have changed. In the old days, a certificate was linked to one static IP address. Now, it's not a problem anymore. It works with any IP and on any server. You just have to copy your private key to all the computers that use your certificate (and make sure it's secure.) – Alexis Wilke Jun 29 '18 at 00:11
  • Ahh, fair enough - I just had to do a deep-dive on SSL certs (still generally confused), and it does seem like they've been able to expand functionality over time. Thanks for chiming in on a comment from ~2 years ago! – dwanderson Jun 29 '18 at 00:13
14

YES, you can use the same certificate and associated private key on all of your servers, if they are behind a load balancer or load balancing reverse proxy and if they are all serving content for the same domain.

Certificates, when signed by a certificate authority, assert that the certificate authority verified the name listed on the certificate. For certificates for websites, that means the website's domain name. Your browser expects that the server it is talking to, if it is talking over HTTPS, presents a certificate bearing the same name as the domain name that the browser thinks it is talking to. (For example, VeriSign is not likely to sign Hacker Joe's certificate for bankofamerica.com. So even if Hacker Joe manages to intercept traffic between you and bankofamerica.com, Hacker Joe won't have a signed certificate for bankofamerica.com and your browser will put up big red warning flags all over the place.)

What matters is that the name on the certificate matches the domain name that the browser thinks it is talking to. You can use the same certificate (with associated private key) bearing the correct name across multiple web servers in a web cluster, so long as they are behind a load balancer.

You can also use an SSL-terminating load balancer, in which case you would use the certificate (with associated private key) on the load balancer, and the web servers wouldn't need certificates because they wouldn't be having anything to do with the SSL.

yfeldblum
  • 368
  • 2
  • 3
7

Our setup has worked very well:

https trafic
     |
   pound
     |
http traffic
     |
  haproxy
     |
http traffic 
     |
web server 1 ... web server n

This way pound decrypts the traffic, from here on everything is straight http. Advantages: less configuration on the web servers, one tool for each job. You can max out the CPU on the pound machine, and keep the web servers "normal". You should get at least two of each (pound, haproxy, web servers), if uptime is important.

jotango
  • 465
  • 1
  • 5
  • 10
3

AFAIR, you can use the same cert on each server. You can also implement an SSL accelerator and offload all of the SSL traffic to it.

joeqwerty
  • 108,377
  • 6
  • 80
  • 171