Azure上通過haproxy實現APP Gateway或WAF的http跳轉https


Azure上的APP Gateway是七層負載均衡服務,WAF是APP Gateway服務的擴展。在實現七層負載均衡的同時,增加了WAF的功能,可以對后台的HTTP服務進行保護。

Azure WAF采用的是開源的ModSecurity的OWASP core rule sets實現的WAF功能。具體請參考ModSecurity的網站:https://modsecurity.org/

目前Azure支持OWASP CRS的版本有3.0和2.2.9兩個版本。並可以根據需求,enable或disable庫中的某個功能:

本文將介紹,目前APP Gateway和WAF還不支持的一個功能:Http跳轉到Https借助Haproxy實現。

一、拓撲結構

具體的結構如下:

1. 用戶發起http請求,

2. APP Gateway根據后端的Server情況,轉發到后台的haproxy的80端口,

3. Haproxy收到http請求后,做http的redirect,到APP Gateway的https

4. 用戶發起https請求

5. APP Gateway進行SSL的offload,如果配置了WAF,將對http內容進行檢測,防止各種攻擊

6. APP Gateway根據后端的Server情況,轉發8080端口到haproxy,haproxy將8080的請求轉發到Nginx的800端口。

二、 APP Gateway的配置

具體創建過程不再描述了,具體描述http和https的兩種rule的定義:

1. listener

配置http和https兩個listner

2. rules

http的rules:

Httpsd rules:

3. http setting

添加https的設置:

 

其它的采用默認配置就ok。

三、Haproxy的配置

在VM中安裝haproxy,並增加如下配置:

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:80
mode http
redirect location https://x.x.x.x
frontend main *:8080
mode http
default_backend static
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:800 check

可以看到,haproxy監聽80和8080兩個端口。80端口的請求將直接轉發到app gateway的https,8080端口將轉發給800端口的Nginx服務。

四、Nignx配置

Nginx只需要把服務端口改為800即可。

五、測試

瀏覽器輸入APP Gateway的地址:

http://139.219.232.180/

將會轉發到https:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM