Skip to content

Instantly share code, notes, and snippets.

@foxel
Last active June 26, 2017 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxel/c13a5096c1bf616be44d to your computer and use it in GitHub Desktop.
Save foxel/c13a5096c1bf616be44d to your computer and use it in GitHub Desktop.
Haproxy + letsencrypt + docker
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend http-in
bind *:80
# comment this out on first run
bind *:443 ssl crt /etc/haproxy/ssl-bundle.pem
default_backend failback
acl host_example1 hdr_dom(host) -i example1.com
acl host_example2 hdr_dom(host) -i example2.com
acl path_letsencrypt path_beg /.well-known/acme-challenge
use_backend letsencrypt if path_letsencrypt
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
use_backend example1 if host_example1
use_backend example2 if host_example2
backend example1
option http-server-close
redirect scheme https if !{ ssl_fc }
server server1 localhost:9000 check inter 10000 maxconn 50
backend example2
option http-server-close
redirect scheme https if !{ ssl_fc }
server server1 localhost:9010 check inter 10000 maxconn 50
backend letsencrypt
option http-server-close
server server1 localhost:9080 maxconn 50
backend failback
http-request deny
#!/bin/bash
set -e
DOMAINS="example1.com,example2.com"
EMAIL="admin@example1.com"
docker run --rm -v /etc/letsencrypt:/etc/letsencrypt -p 9080:80 \
quay.io/letsencrypt/letsencrypt \
certonly --standalone --agree-tos --renew-by-default --standalone-supported-challenges http-01 \
--email $EMAIL -d $DOMAINS
read -d ',' CERT_DOMAIN <<< "${DOMAINS},"
cat /etc/letsencrypt/live/$CERT_DOMAIN/fullchain.pem /etc/letsencrypt/live/$CERT_DOMAIN/privkey.pem > /etc/haproxy/ssl-bundle.pem
service haproxy reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment