haproxy代理https配置方法

來源:互聯網
上載者:User

標籤:

 

 

 

記得在之前的一篇文章中介紹了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配置方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.