HAproxy子目录 [英] HAproxy subdirectory
问题描述
我一直在尝试Internet的深度,试图让HAProxy发挥作用,但我不确定它能否实现我想要的功能.
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.
我尝试了以下操作: https://www.haproxy.com/blog/howto-write-apache-proxypass-rules-in-haproxy/
这是我的情况:我有一个在端口8999上运行app1的VM.当我转到https://PUBLIC-IP-ADDRESS/app1
时,HAProxy应该在http://backend-ip:8999/
处显示app1的根目录.
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/
.
我面临的问题是我可以让HAProxy代理初始连接,但所有后续请求都将到达默认后端服务器的根.
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
现在可以转到/app1/
,但是所有链接都指向/
.因此,单击任意位置都会使我回到https://PUBLIC-IP-ADDRESS
.
Going to /app1/
now works but all links point to /
. So clicking anywhere brings me back to https://PUBLIC-IP-ADDRESS
.
非常感谢您的帮助.
推荐答案
resirep
仅允许修改标头和请求行.
resirep
allow to modify headers and request line only.
使用1.6版以上的新版本,可以使用lua脚本(以有限的方式) ...但是目前尚无通用的(成功的)解决方案(作为参考 http://www.serverphorums.com/read.php?10,1322511 ).
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).
也是正式邮件列表- https://www.mail- archive.com/haproxy@formilux.org/msg25215.html ,没有任何幻想.
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.
无需重写的解决方案:
- 在/app1上使应用程序可用-如果您可以控制
- 有点像上面-根据haproxy的某些标头(x-forwarded-path?)设置
<base>
- 放弃
/app1
路径并使用子域(我会选择这个域)
- make app available on /app1 - if you are in control of it
- a bit like above - set
<base>
based on some header (x-forwarded-path?) from haproxy - give up with the
/app1
path and use subdomains (I would choose this one)
这篇关于HAproxy子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!