ฉันใช้ HAproxy 1.6 เป็น load balancer หน้าเซิร์ฟเวอร์ Tomcat
ฉันต้องการเพิ่มส่วนหัวการตอบกลับตามคำขอ URI
ตัวอย่างเช่นฉันต้องการเพิ่มหัวข้อการตอบกลับCache-Control public,max-age="600"เมื่อคำขอ uri เป็น/apiแต่ไม่ใช่เมื่อคำขอ uri เป็นอย่างอื่น
ความพยายามครั้งแรกของฉันคือการใช้ acl ตามเส้นทางเพื่อเพิ่มส่วนหัวในการตอบสนอง http:
acl api path_reg ^/api/(.*)$ http-response add-header Cache-Control public,max-age="600" if apiเมื่อฉันเริ่ม 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'ฉันพยายามเพิ่มส่วนหัว
http-requestแทนhttp-response:acl api path_reg ^/api/(.*)$ http-request add-header Cache-Control public,max-age="600" if apiมันใช้งานได้ แต่ฉันต้องการมันในการตอบกลับ
ฉันยังพยายามใช้ตัวแปร haproxy:
http-request set-var(txn.path) path acl path_acl %[var(txn.path)] -m ^/api/(.*)$ http-response add-header Cache-Control public,max-age="600" if path_aclแต่เมื่อฉันลอง HAproxy ไม่เริ่มต้นเหตุการณ์และฉันมีข้อผิดพลาดดังต่อไปนี้:
[ALERT] 340/162647 (2241) : parsing [/etc/haproxy/haproxy.cfg:48] : error detected while parsing ACL 'path_acl' : unknown fetch method '%[var' in ACL expression '%[var(txn.path)]'.
ฉันจะใช้เส้นทางคำขอเป็น acl เพื่อตั้งหัวข้อการตอบสนองได้อย่างไร
capture.req.uriและตัวแปรในขณะที่ถอด%[ ]ในacl̀กำลังทำงาน คุณยังต้องเกี่ยวกับคำพูดรอบmax-ageคุ้มค่าและแทนset-headeradd-header