【发布时间】:2020-01-25 08:29:17
【问题描述】:
如何配置路由器的 ha-proxy 以便选择传入呼叫的标头并可能添加其他传出标头...
我只想为来自特定主机名或具有特定标头的呼叫附加一个新标头
【问题讨论】:
如何配置路由器的 ha-proxy 以便选择传入呼叫的标头并可能添加其他传出标头...
我只想为来自特定主机名或具有特定标头的呼叫附加一个新标头
【问题讨论】:
可以通过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
希望对你有帮助。
【讨论】:
我的配置文件是这样的...假设我们要添加一个带有值的新标头...
所以我只需要添加一行: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*
【讨论】: