haproxy5-ssl

配置实例:

https://andyleonard.com/2011/02/01/haproxy-and-keepalived-example-configuration

配置haproxy支持https协议:

       1 支持ssl会话

                   Bind  *:443  ssl  crt  /PATH/TO/SOME_PEM_FILE(这的证书和私钥是合二唯一的)

                 Crt 后的证书文件要求PEM格式,且同时包含证书和之匹配的所有私钥

                   Cat  demo.crt  demo.key  >  demo.pem

         2 把端口80的请求重定向443

                   Bind  *:80

                   Redirect  scheme  https  if  !{ ssl_fc }------这是个内建变量

            #对非ssl的访问的任何url都重定到https的主页上

                   Redirect  location  https://172.16.0.67/  if  !{ ssl_fc }

         3 如何向后端传递用户请求的协议和端口

                   http_request  set-header  X-Forwarded-port  %[dst_port] 

                   http_request  add-header  X-Forwaed-Proto https if { ssl_fc }

Frontend  https
    Bind  *:443  ssl  crt  /etc/haproxy/certs/haproxy.pem
    Acl  stats  path_end  .ipg  .txt  .html
    Use_backend  staticserver  if stats
    Default_backend  dynsrvs
Frontend  http
    Bind  *:80
    Redirect  scheme  https  if !{ ssl_fc }   #重定向
#创建ssl签证
#cd  /etc/pki/CA/
# (umask 077;openssl  gentsa  -out  private/cakey.pem  4096)  ca秘钥
# openssl req  -new  -x509  -key  private/cakey.pem  -out  cacert.pem  -day  365 自签证书
# touch  index.txt
#echo 01 > serial

#cd  /etc/haproxy/certs
#openssl genrsa  -out  haproxu.key  2048   创建秘钥
#openssl   req  -new  -key  haproxy.key  -out  haproxy.csr   签证
#openssl  ca  -in haproxy.csr  -out  haproxy.crt   ca签证

将key与crt  打包起来合并在一个文件中
#cat  haproxy.key  haproxy.crt  >  haproxy.pem
#chmod  600  haproxy.pem
#创建ssl签证

猜你喜欢

转载自www.cnblogs.com/huxl1/p/10791637.html
SSL