Redirect 如何在响应中使用附加标题重定向?

Redirect 如何在响应中使用附加标题重定向?,redirect,haproxy,cache-control,Redirect,Haproxy,Cache Control,目前,我使用haproxy将一些域自动升级为https到https。我使用代码308是因为我没有找到添加Expires:Thu,2014年12月1日16:00:00或Cache Control:max age=3600标题的可能性 frontend http-frontend bind *:80 mode http redirect scheme https code 307 if { hdr(Host) -i foo.example.com } !{ ssl_fc }

目前,我使用haproxy将一些域自动升级为https到https。我使用代码308是因为我没有找到添加
Expires:Thu,2014年12月1日16:00:00
Cache Control:max age=3600
标题的可能性

frontend http-frontend
    bind *:80
    mode http
    redirect scheme https code 307 if { hdr(Host) -i foo.example.com } !{ ssl_fc }
    redirect scheme https code 307 if { hdr(Host) -i bar.example.com } !{ ssl_fc }

如何修改上述重定向规则以在响应中包含
缓存控制
头?

HAProxy使用“http请求集头”指令在响应中插入头。 不幸的是,在撰写本文时,这仅在HAProxy从后端获取流量时可用。
“http请求重定向…”(或“重定向”)是前端的最终指令,在这种情况下没有后端响应。 关键是创建一个虚拟后端,如下所示:

frontend http-frontend
    bind *:80
    mode http
    use_backend be_dummy_redirect if { hdr(Host) -i foo.example.com } !{ ssl_fc }
    use_backend be_dummy_redirect if { hdr(Host) -i bar.example.com } !{ ssl_fc }
    default_backend be_app

 backend be_dummy_redirect
    http-response set-header Expires "Thu, 01 Dec 2014 16:00:00"
    http-response set-header Cache-Control max-age=3600
    server redirect-server 127.0.0.1:9000

 listen redirect
    bind 127.0.0.1:9000
    http-request redirect scheme https

这在开发人员之前就已经有了,也许将来会实施

我将在后天对此进行测试。但我已经有一个评论:第三层真的有必要吗?也就是说,如果我将
服务器重定向服务器127.0.0.1:9000
替换为
http请求重定向方案https
,它会失败吗?是的,因为将“http请求重定向”(或传统形式的“重定向”)放在后端将是一个最终指令,这意味着HAProxy不会将请求发送到后端,而是直接用重定向进行应答。因此,“http响应”指令将不会被处理。final指令基本上意味着这些指令在执行行中上移,执行在第一个final指令之后终止。明白了。谢谢