Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

如何搭建HTTPS的云WAF

0
0
前言

如何建立云WAF这篇文章讲述了我构造http的云WAF的经历。最近博客迁移到了https,所以就存在一个「https的WAF环境,应该如何配置」的问题。

如何配置

在手上没有什么资料的前提下,我开始进行大胆猜测。我们知道这个过程一定是:

访问 https://joychou.org DNS服务器CNAME到waf.joychou.me域名 waf.joychou.me服务器解析server_name为 waf.joychou.me 并且端口为443的block,并将流量进行反向代理转发到后端服务器

前面2步都没问题,那就只有第三步的可能会有问题了。要转发 https://joychou.org 的流量,肯定需要 https://joychou.org 网站的https证书和私钥。所以在 waf.joychou.me 的server block先配上 https://joychou.org 的证书和私钥。

现在的配置如下:

server { listen 443; server_name waf.joychou.me; ssl on; ssl_certificate /usr/local/nginx/ssl/chained.pem; ssl_certificate_key /usr/local/nginx/ssl/domain.key; location / { proxy_buffers 8 16k; proxy_buffer_size 32k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass https://x.x.x.x; } }

设置 proxy_buffer ,是为了解决一个502的error,可忽略。这个时候,访问 https://joychou.org 已经可以正常访问了,WAF也能正常拦截。

但是,一般的云waf的域名,不会让直接访问。比如,我们先ping下 www.aliyun.com ,WAF的域名是 sh.wagbridge.aliyun.com.gds.alibabadns.com ,直接访问返回404,如果该WAF域名能直接访问,那访问的效果等同于 www.aliyun.com ,所以肯定是有问题的,那就需要设置。

不过,只要我们设置下host就能访问了: curl -v -H 'host:www.aliyun.com' 'https://sh.wagbridge.aliyun.com.gds.alibabadns.com/?'

所以,根据host来配置就行。添加以下配置:

if ($host != 'joychou.org') { return 404 "Good Game"; } 配置

443端口配置:

server { listen 443; server_name waf.joychou.me; ssl on; ssl_certificate /usr/local/nginx/ssl/chained.pem; ssl_certificate_key /usr/local/nginx/ssl/domain.key; if ($host != 'joychou.org') { return 404 "Good Game"; } location / { proxy_buffers 8 16k; proxy_buffer_size 32k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass https://x.x.x.x; } }

这样,配置完成后,访问 https://joychou.org 就已经没有问题了。不过还需要对80端口进行一个rewrite到https的操作。

80端口配置:

server { listen 80; server_name waf.joychou.me; if ($host != 'joychou.org') { return 404 "Good Game"; } rewrite ^(.*) https://$host$1 permanent; } 总结

云WAF就是将所有的域名、IP、端口、协议做成配置化,而不是向我文中的硬编码。


如何搭建HTTPS的云WAF

微信打赏


如何搭建HTTPS的云WAF

支付宝打赏


如何搭建HTTPS的云WAF

扫描二维码,在手机上阅读!


Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles





Latest Images