SSL termination
dockercloud/haproxy
supports ssl termination on multiple certificates. For each application that you want ssl terminates, simply set SSL_CERT
and VIRTUAL_HOST
. HAProxy, then, reads the certificate from the link environment and sets the ssl termination up.
Attention: there was a bug that if an environment variable value contains "=", which is common in the SSL_CERT
, docker skips that environment variable. As a result, multiple ssl termination only works on docker 1.7.0 or higher, or in Docker Cloud.
SSL termination is enabled when:
- at least one SSL certificate is set, and
- either
VIRTUAL_HOST
is not set, or it is set with "https" as the scheme.
To set SSL certificate, you can either:
- set
DEFAULT_SSL_CERT
indockercloud/haproxy
, or - set
SSL_CERT
and/orDEFAULT_SSL_CERT
in the application services linked to HAProxy
The difference between SSL_CERT
and DEFAULT_SSL_CERT
is that, the multiple certificates specified by SSL_CERT
are stored in as cert1.pem, cert2.pem, ..., whereas the one specified by DEFAULT_SSL_CERT
is always stored as cert0.pem. In that case, HAProxy will use cert0.pem as the default certificate when there is no SNI match. However, when multiple DEFAULT_SSL_CERTIFICATE
is provided, only one of the certificates can be stored as cert0.pem, others are discarded.
PEM Files
The certificate specified in dockercloud/haproxy
or in the linked application services is a pem file, containing a private key followed by a public certificate(private key must be put before the public certificate and any extra Authority certificates, order matters). You can run the following script to generate a self-signed certificate:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out ca.pem -days 1080 -nodes -subj '/CN=*/O=My Company Name LTD./C=US'
cp key.pem cert.pem
cat ca.pem >> cert.pem
Once you have the pem file, you can run this command to convert the file correctly to one line:
awk 1 ORS='\\n' cert.pem
Copy the output and set it as the value of SSL_CERT
or DEFAULT_SSL_CERT
.