Hi Sean,
On Fri, Jan 06, 2012 at 02:16:44PM -0500, Sean Patronis wrote:
> Well, I think I figured it out. Though I am not sure it is the most
> efficient way.....
>
> first I created a match acl in the frontend:
>
> acl is_apps_match url_dir apps
>
> then in the backend, i created a rewrite:
> reqrep ^([^\ ]*)\ /apps/(.*) \1\ /\2
It is exactly the principle. However you have to keep in mind that
remapping URLs is almost always the wrong thing to do, because your
application's URL will not match the browser's URLs anymore, and
while it can work fine at the beginning, in the long term you'll
surely regret it. For instance, you'll have to rewrite your Location
headers in redirects too. If your application presents some absolute
links, you'll have to change them. Once you do that, you can't test
your application anymore by directly connecting to it with a browser,
you'll have to connect through haproxy, which makes developments
more cumbersome.
It's important never to forget this rule : "rewrite rules always
implies more rewrite rules" and you can never get out of that
spiral.
> Is there a more efficient way?
The most efficient way is simply not to transform them and have
your application server rely on the host and path since they're
left untouched.
However concerning the frontend rules, you can factor them out :
acl redir-app1 url_beg /app1
acl redir-app2 url_beg /app2
acl redir-app3 url_beg /app3
use_backend apps_cluster if redir-app1
use_backend apps_cluster if redir-app2
use_backend apps_cluster if redir-app3
May become (1) :
acl redir-app url_beg /app1
acl redir-app url_beg /app2
acl redir-app url_beg /app3
use_backend apps_cluster if redir-app
Then (2) :
acl redir-app url_beg /app1 /app2 /app3
use_backend apps_cluster if redir-app
And then (3) :
use_backend apps_cluster if { url_beg /app1 /app2 /app3 }
The third form is only handy for short URLs when you have many different
app clusters, because it makes the switching rules more readable. In your
situation, if you have only one app cluster, the second form is probably
much better, because you can have for instance one "acl" line per hosted
application with its various possible URLs on the same line.
Regards,
Willy