小编jml*_*lrt的帖子

如何根据请求 URI 使用 HAproxy 1.6 添加响应标头?

我在 tomcat 服务器前使用 HAproxy 1.6 作为负载平衡器。

我需要根据请求 URI 添加响应标头。

例如,Cache-Control public,max-age="600"当请求 uri 是/api但不是当请求 uri 是其他东西时,我想添加响应头。

  • 我的第一次尝试是使用基于路径的 acl 将标头添加到 http-response:

    acl api path_reg ^/api/(.*)$
    http-response add-header Cache-Control public,max-age="600" if api
    
    Run Code Online (Sandbox Code Playgroud)

    当我用 开始haproxy 时-d,我有警告说path_reg(或path)与http-response以下不兼容:

    Dec  6 15:22:29 ip-10-30-0-196 haproxy-systemd-wrapper[315]: 
    [WARNING] 340/152229 (2035) : parsing 
    [/etc/haproxy/haproxy.cfg:78] : acl 'api' will never match because 
    it only involves keywords that are incompatible with 'backend 
    http-response header rule'
    
    Run Code Online (Sandbox Code Playgroud)
  • 我试图添加标题http-request而不是http-response

    acl …
    Run Code Online (Sandbox Code Playgroud)

cache http-headers haproxy

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

cache ×1

haproxy ×1

http-headers ×1