首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HAProxy在302重定向之前添加一些标头

HAProxy在302重定向之前添加一些标头
EN

Stack Overflow用户
提问于 2018-06-14 18:41:35
回答 1查看 2.2K关注 0票数 1

我试图在指向特定端口的响应中添加一些安全头。我配置了以下前端:

代码语言:javascript
复制
frontend desenv_ext_1 
bind *:80 
bind *:443  ssl crt /etc/ssl/certs/cert.pem 
mode http 
option tcplog 
default_backend desenv_1 
timeout client          5m

#ACL to new attempt 
acl header_c dst_port 80

#Attempt with no ACL 
http-response set-header X-Frame-Options SAMEORIGIN 

#Attempt with ssl ACL 
http-response set-header Strict-Transport-Security max-age=31535400;\ includeSubDomains;\ preload; if {ssl_fc} 
http-response add-header Referrer-Policy no-referrer if !{ ssl_fc }

#Attempt with header_c ACL 
http-response set-header X-Content-Type-Options nosniff if header_c 
http-response add-header X-XSS-Protection 1;\ mode=block if header_c

#Attempt with rspadd 
rspadd X-Backen-Serve\ laranja if header_c 
rspadd X-Backend-Serve\ caju if HTTP

redirect scheme https if !{ ssl_fc }

您可以看到,在配置中,有些测试以不同的方式进行,而这两种方法都不起作用。

重定向工作正常,但端口80响应中没有添加标头:

代码语言:javascript
复制
[root@managerr temp]# curl -I http://localhost
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-length: 0
Location: https://localhost/
Connection: close

我希望到达端口80的请求添加以下标头,即使它们重定向到端口443:

代码语言:javascript
复制
Strict-Transport-Security max-age=31535400;\ includeSubDomains;\ preload;
X-Frame-Options SAMEORIGIN
X-Content-Type-Options nosniff
X-XSS-Protection 1;\ mode=block

我需要的输出是:

代码语言:javascript
复制
HTTP/1.1 302 Found
Strict-Transport-Security max-age=31535400;\ includeSubDomains;\ preload;
X-Frame-Options SAMEORIGIN
X-Content-Type-Options nosniff
X-XSS-Protection 1;\ mode=block
Cache-Control: no-cache
Content-length: 0
Location: https://localhost/
Connection: close

后端:

代码语言:javascript
复制
backend desenv_1
mode http
option tcplog
server manga x.x.x.x:80 check cookie manga
timeout connect        10s
timeout server          5m

我的HA-代理版本1.5.18

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-15 01:13:44

redirecthttp-response之前被执行,因此这些http-response永远不会被执行。

用这个:

代码语言:javascript
复制
http-request redirect location "https://%[hdr(host)]%[url]\r\nX-Frame-Options: SAMEORIGIN\r\nReferrer-Policy: no-referrer"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50863941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档