先来看两个haproxy中内容指令

req.hdr  #对请求报文中的内容做检查

res.hdr  #对请求报文中的内容做检查

样例:

acl h_xff_exists req.hdr(X-Forwarded-For) -m found                                                 #判断请求头X-Forwarded-For是否存在

http-request replace-header X-Forwarded-For (.*) %[src],1 if h_xff_exists                #如果存在X-Forwarded-For头替换掉

acl h_xff_exists res.hdr(X-Frame-Options) -m found                                                 #判断响应头X-Frame-Options是否存在

http-response set-header X-Frame-Options SAMEORIGIN if !h_xff_exists              #如果后端响应不存在X-Frame-Options头

参考文章:

https://www.haproxy.com/documentation/hapee/1-7r1/traffic-management/http-rewrite/

https://cbonte.github.io/haproxy-dconv/1.5/configuration.html#1.3.2

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注