我正在使用HAProxy代理对应用程序的请求,该应用程序在同一台计算机上的docker容器中托管了不同的部署。最终目标是在不更改网址的情况下向http://remote-machine/appname/deploy1(主机)代理http://remote-machine:810x/appname-deploy1(docker容器)请求。
以下是我的配置文件。如果我包含尾部斜杠(例如“:// remote-machine / appname / deploy1 /”),它将按预期工作。在这种情况下,URL不会更改,并从“:// remote-machine:810x / appname-deploy1”
中检索内容如果我省略了尾部斜杠,导航到“:// remote-machine / appname / deploy1”会错误地将网址重写为“:// remote-machine / appname-deploy1”,并且我收到404错误,因为端口未指定。无论哪种方式,我都不希望为用户重写URL,我只需要确保它代理到应用程序部署的正确地址。
我是HAProxy的新手,所以任何建议都会受到赞赏。谢谢!
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
acl deployment1 url_beg /appname/deploy1 -i
acl deployment2 url_beg /appname/deploy2 -i
acl app-landing url_beg /appname -i
use_backend docker1 if deployment1
use_backend docker2 if deploymen2
use_backend docker3 if app-landing
backend docker1
# We need to rewrite the url so that /appname/deploy1 proxies to /appname-deploy1 on the docker container
# E.g. http://remote-machine/appname/deploy1 loads content from http://remote-machine:8101/appname-deploy1
reqrep ^([^\ :]*)\ /appname/deploy1(.*) \1\ /appname-deploy1\2
server host1 remote-machine:8101
backend docker2
reqrep ^([^\ :]*)\ /appname/deploy2(.*) \1\ /appname-deploy2\2
server host1 remote-machine:8102
backend docker3
reqrep ^([^\ :]*)\ /appname(.*) \1\ /appname-landing\2
server host1 remote-machine:8103