首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Openshift上的自定义Ha-proxy

Openshift上的自定义Ha-proxy
EN

Stack Overflow用户
提问于 2019-09-25 07:38:16
回答 2查看 303关注 0票数 0

如何配置路由器的ha-proxy,以便在传入呼叫的报头上进行选择,并可能添加其他传出报头……

我只想为来自特定主机名或具有特定标头的调用附加一个新标头

EN

回答 2

Stack Overflow用户

发布于 2019-09-25 08:57:10

您可以通过Obtaining the Router Configuration Template获取默认的haproxy模板。

代码语言:javascript
运行
AI代码解释
复制
# 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

代码语言:javascript
运行
AI代码解释
复制
# vim haproxy-config.template

自定义完成后,需要通过Using a ConfigMap to Replace the Router Configuration Template步骤将模板替换为当前模板。

代码语言:javascript
运行
AI代码解释
复制
$ 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

我希望它能对你有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2019-09-26 09:38:41

我的配置文件是这样的……让我们假设我们想要添加带有值的新头文件……

所以我只需要添加一行: http-request add-header new_header_name:value?

但是,如果我只想为输入中的特定主机名添加新的标头,我该怎么办呢?

代码语言:javascript
运行
AI代码解释
复制
*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*
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58093441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档