小编Mat*_*ley的帖子

HAProxy 子域和路径重定向

我是 StackExchange 的新手,正在尝试寻找一些有关配置问题的帮助。我需要为 HAProxy 创建一个配置,它允许我将 Tomcat 应用程序上下文路径动态代理到子域。子域/路径不能硬编码,应设置为变量。我已经查看了整个站点中建议的其他内容,但没有一个涉及这个特定问题。到目前为止,我已经从各种现有建议中汇总了此配置。

这就是我需要的。

  • 用户请求 -> http://site1.domain.com/path
  • 重定向到 https
  • HAProxy 然后使用 URL 向其后端池发出请求 http://<ip>:8080/site1/path

当 tomcat 应用程序返回指向资产的链接时,它们也会有一个需要重定向的路径。

  • 网站退货 https://site1.example.com/site1/image.jpg
  • 如果存在,从路径中删除第一个 site1。 https://site1.example.com/image.jpg

我已经使用本网站的示例和其他指南获得了这么多,但我在这方面的知识有限。我不确定如何删除路径中的 site1。

# Frontend Definition
frontend tomcat_contexts
    bind *:80
    bind *:443 ssl crt /etc/haproxy/cert.pem
    acl http ssl_fc,not
    http-request redirect scheme https if http
    reqadd X-Forwarded-Proto:\ https
    default_backend cluster

# Backend Definition
backend cluster
    balance roundrobin
    cookie JSESSIONID prefix nocache

    # Perform Subdomain url rewrite
    http-request set-var(req.subdomain) req.hdr(host),lower,regsub(\.example\.com$,) if { hdr_end(host) -i .domain.com }
    http-request …
Run Code Online (Sandbox Code Playgroud)

configuration tomcat subdomain haproxy

5
推荐指数
0
解决办法
1302
查看次数

标签 统计

configuration ×1

haproxy ×1

subdomain ×1

tomcat ×1