標籤:
記得在之前的一篇文章中介紹了nginx反向 Proxyhttps的方法,今天這裡介紹下haproxy代理https的方法:
haproxy代理https有兩種方式:
1)haproxy伺服器本身提供ssl認證,後面的web伺服器走正常的http
2)haproxy伺服器本身只提供代理,後面的web伺服器走https(配置ssl認證)
第一種方式:haproxy伺服器本身提供ssl認證
注意:
需要編譯haproxy的時候支援ssl
編譯參數:
#make TARGET=linux26 USE_OPENSSL=1 ADDLIB=-lz
#ldd haproxy | grep ssl
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fb0485e5000)
配置參數(修改haproxy.cfg檔案)
frontend https_frontend
bind *:443 ssl crt /etc/ssl/certs/servername.pem
mode http
option httpclose
option forwardfor
reqadd X-Forwarded-Proto:\ https
default_backend web_server
backend web_server
mode http
balance roundrobin
cookie SERVERID insert indirect nocache
server s1 192.168.1.150:80 check cookie s1
server s2 192.168.1.151:80 check cookie s2
-----------------------------------------------------------
注意:這裡的pem 檔案是下面兩個檔案合并而成:
#cat servername.crt servername.key |tee servername.pem
-----------------------------------------------------------
第二種方式:haproxy伺服器本身只提供代理,沒有ssl認證 (一般我們常用的就是這種方式)
這種方式,haproxy不需要重新編譯支援ssl,簡單方便,只需要後面的web伺服器配置好ssl即可。
配置參數(修改haproxy.cfg檔案)
frontend https_frontend
bind *:443
mode tcp
default_backend web_server
backend web_server
mode tcp
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
server s1 192.168.1.150:443
server s2 192.168.1.151:443
---------------------------------------------------------
注意,這種模式下mode 必須是tcp 模式
---------------------------------------------------------
haproxy代理https配置方法