Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAPROXY multiple context based routing not working #1

Open
sathishece170 opened this issue Feb 19, 2019 · 6 comments
Open

HAPROXY multiple context based routing not working #1

sathishece170 opened this issue Feb 19, 2019 · 6 comments

Comments

@sathishece170
Copy link

Im having below haproxy configuration to route two urls based on context path. But during my testing found that app1 is always working fine and app2 is not working but routed to app1 itself.

Using reqirep to ignore the context path while routing to application (this is needed by my application)

From browser i will call like,

http://test.com/app1 should be routed to app1
http://test.com/app2 should be routed to app2

Any help would be appreciated?

frontend http_frontend
    bind *:80
    mode http
http-response set-header Strict-Transport-Security max-age=15768000
reqirep  ^([^\ :]*)\ /app1(.*) \1\ /\2
reqirep  ^([^\ :]*)\ /app2(.*) \1\ /\2
###################### ACL ###########################
 acl acl_app1 hdr_dom(host) test.com path_beg -i /app1
  use_backend acl-backend_app1 if acl_app1
###################### ACL ###########################
 acl acl_app2 hdr_dom(host) test.com path_beg -i /app2
  use_backend acl-backend_app2 if acl_app2
###################### ACL ###########################'
@kamleshchandnani
Copy link
Owner

kamleshchandnani commented Feb 20, 2019

There are few thing you're confusing them.

  1. reqirep won't redirect your path so your acl check will fail.
  2. your acl check for /app1 will only pass if your request path contains /app1 and not reqirep.

if from your browser you are directly making a call http://test.com/app1 then you don't even need reqirep

frontend http_frontend
    bind *:80
    mode http
http-response set-header Strict-Transport-Security max-age=15768000
###################### ACL ###########################
 acl acl_app1 hdr_dom(host) test.com path_beg -i /app1
  use_backend acl-backend_app1 if acl_app1
###################### ACL ###########################
 acl acl_app2 hdr_dom(host) test.com path_beg -i /app2
  use_backend acl-backend_app2 if acl_app2
###################### ACL ###########################'

@sathishece170
Copy link
Author

As per your code snippet request with /app1 works fine but /app2 doesnt since when request comes it matches the host with /app1 filter & failed. It never go and match the regex with second acl filter because of same host.

@kamleshchandnani
Copy link
Owner

try this

frontend http_frontend
    bind *:80
    mode http
http-response set-header Strict-Transport-Security max-age=15768000
acl is-test-app hdr_dom(host) -i test.com
###################### ACL ###########################
 acl is-app1 path_beg -i /app1
 use_backend backend_app1 if is-app1 is-test-app
###################### ACL ###########################
 acl is-app2 path_beg -i /app2
 use_backend backend_app2 if is-app2 is-test-app

@sathishece170
Copy link
Author

Thanks for responding!

I have tried this already but it is asking for username and password after adding this when i hit the url. This looks strange to me as i have not enabled security here.

Will HAProxy version matters since i'm using 1.8.1?

@kamleshchandnani
Copy link
Owner

Not sure but previously it wasn't working because you shouldn't put conditions in acls and because your first check was for host that's why it was going to /app1 always with #1 (comment) that would be fixed.

@sathishece170
Copy link
Author

Ok. I will check it and thanks for your help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants