如何配置路由器的ha-proxy,以便在传入呼叫的报头上进行选择,并可能添加其他传出报头……
我只想为来自特定主机名或具有特定标头的调用附加一个新标头
发布于 2019-09-25 08:57:10
您可以通过Obtaining the Router Configuration Template获取默认的haproxy模板。
# oc get po
NAME READY STATUS RESTARTS AGE
router-2-40fc3 1/1 Running 0 11d
# oc rsh router-2-40fc3 cat haproxy-config.template > haproxy-config.template
然后您可以自定义模板,例如通过haproxy配置添加额外的header。有关路由器模板的详细信息,请参阅Go Template Actions;有关haproxy配置的详细信息,请参阅http-request set-header。
# vim haproxy-config.template
自定义完成后,需要通过Using a ConfigMap to Replace the Router Configuration Template步骤将模板替换为当前模板。
$ oc create configmap customrouter --from-file=haproxy-config.template
$ oc set volume dc/router --add --overwrite \
--name=config-volume \
--mount-path=/var/lib/haproxy/conf/custom \
--source='{"configMap": { "name": "customrouter"}}'
$ oc set env dc/router \
TEMPLATE_FILE=/var/lib/haproxy/conf/custom/haproxy-config.template
我希望它能对你有所帮助。
发布于 2019-09-26 09:38:41
我的配置文件是这样的……让我们假设我们想要添加带有值的新头文件……
所以我只需要添加一行: http-request add-header new_header_name:value?
但是,如果我只想为输入中的特定主机名添加新的标头,我该怎么办呢?
*frontend public
bind :80
mode http
tcp-request inspect-delay 5s
tcp-request content accept if HTTP
monitor-uri /_______internal_router_healthz
# Strip off Proxy headers to prevent HTTpoxy (https://httpoxy.org/)
http-request del-header Proxy
# DNS labels are case insensitive (RFC 4343), we need to convert the hostname into lowercase
# before matching, or any requests containing uppercase characters will never match.
http-request set-header Host %[req.hdr(Host),lower]
# check if we need to redirect/force using https.
acl secure_redirect base,map_reg(/var/lib/haproxy/conf/os_route_http_redirect.map) -m found
redirect scheme https if secure_redirect
use_backend %[base,map_reg(/var/lib/haproxy/conf/os_http_be.map)]
default_backend openshift_default*
https://stackoverflow.com/questions/58093441
复制