如果要启用HTTPS,我们就需要从证书授权机构(以下简称CA) 处获取一个证书,Let’s Encrypt 就是一个 CA。 Let’s Encrypt 最初是由EEF 电子前哨基金会、 Mozilla 基金会和美国密歇根大学成立了一个公益组织叫 ISRG ( Internet Security Research Group ),为了加速https推广,在2015 年开始推出的免费证书。后来又有思科(全球网络设备制造商执牛耳者)、 Akamai 加入,甚至连 Linux 基金会也加入了合作,这些大牌组织的加入保证了这个项目的可信度和可持续性。
#!/bin/bash# Directory where the acme client puts the generated certsLETSENCRYPT_CERT_OUTPUT=/etc/letsencrypt/live
# Create or renew certificate for the domain(s) supplied for this tool
certbot renew --dry-run --pre-hook "service nginx start" --post-hook "service nginx stop"# Cat the certificate chain and the private key together for haproxy# for path in $(find $LETSENCRYPT_CERT_OUTPUT/* -type d -exec basename {} \;); do# cat $LETSENCRYPT_CERT_OUTPUT/$path/{fullchain.pem,privkey.pem} > /etc/haproxy/ssl/${path}.pemforpathin$(ls -d $LETSENCRYPT_CERT_OUTPUT/* |grep -o -P "[\w\.-]*$");docat$LETSENCRYPT_CERT_OUTPUT/$path/fullchain.pem $LETSENCRYPT_CERT_OUTPUT/$path/privkey.pem > /etc/haproxy/ssl/${path}.pem
done