HAproxy subdirectory

孤街醉人 提交于 2019-12-12 05:48:37

问题


I've been scouring the depths of the internet trying to get HAProxy to behave but im not sure it can accomplish what I want.

I tried following this: https://www.haproxy.com/blog/howto-write-apache-proxypass-rules-in-haproxy/

Here is my scenario: I've got a VM that is running app1 on port 8999. When I go to https://PUBLIC-IP-ADDRESS/app1 HAProxy should bring up root of app1 at http://backend-ip:8999/.

The issue I'm facing is that I can get HAProxy to proxy the initial connection but all subsequent requests go to the root of the default backend server.

frontend www-https 
  bind *:8989 ssl crt /ssl/server.pem 
  log global 
  option httplog 
  reqadd X-Forwarded-Proto:\ https 
  rspadd Strict-Transport-Security:\ max-age=31536000;\ includeSubDomains 
  acl app1 path_beg -i /app1 /app1/ 
  use_backend www-app1 if app1 
  default_backend www-backend

backend app1 
  option http-server-close
  option forwardfor
  reqirep [\:])\ /app1/(.) \1\ /\2 
  acl hdr_location res.hdr(Location) -m found 
  rspirep Location:\ (https?://Public-IP-ADDRESS(:[0-9]+)?)?(/.*) Location:\ /app1\3 if hdr_location 
  server app1 bk.IP-ADDRESS:8999 check

Going to /app1/ now works but all links point to /. So clicking anywhere brings me back to https://PUBLIC-IP-ADDRESS.

Any help is greatly appreciated.


回答1:


resirep allow to modify headers and request line only.

It the new versions 1.6+, it might be possible (in limited way) with use of lua script ... but currently with no generic (successful) solution (as reference http://www.serverphorums.com/read.php?10,1322511).

The answer in https://serverfault.com/questions/789743/possibility-of-rewriting-response-bodies-in-different-webservers-nginx-apache seems up-to-date.

Also official mailing list - https://www.mail-archive.com/haproxy@formilux.org/msg25215.html, leaves no illusions.

More over, there are many pitfalls - many regexes (or one very complex) to handle all relative (including ../) and absolute variations.

Solution without rewrite:

  1. make app available on /app1 - if you are in control of it
  2. a bit like above - set <base> based on some header (x-forwarded-path?) from haproxy
  3. give up with the /app1 path and use subdomains (I would choose this one)


来源:https://stackoverflow.com/questions/43854804/haproxy-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!