HAProxy子域名和pathredirect

我是StackExchange的新手,我试图find一些configuration问题的帮助。 我需要为HAProxy创build一个configuration,这将允许我dynamic代理一个Tomcat应用程序上下文path到一个子域。 子域/path不能被硬编码,应该设置为一个variables。 我已经看了整个网站的其他build议,但没有一个涵盖了这个特定的问题。 到目前为止,我已经从各种现有的build议中整合了这个configuration。

这是我需要的。

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

tomcat应用程序返回到资产的链接时,他们将有一个path需要redirect。

  • 网站返回https://site1.example.com/site1/image.jpg
  • 如果存在,请从path中删除第一个site1。 https://site1.example.com/image.jpg

我已经使用这个网站的例子和其他指南得到了这个,但我在这方面的知识的极限。 我不知道如何删除path中的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 set-path /%[var(req.subdomain)]%[path] if { var(req.subdomain) -m found } http-request set-header Host example.com if { var(req.subdomain) -m found } # Cluster machines server app01 192.168.69.181:8080 check cookie app01 server app02 192.168.69.182:8080 check cookie app02 

欢迎大家提出意见。