matilu
matilu

Reputation: 276

HAProxy Redirect URL

I am using HAProxy 1.8, I need to make redirection rules, but I do not know the tool well, I have tried but it fails me in some particular cases with different clients.

Client Applications: Adobe Flex 3 (Web) and .Net (Web, WebServices and Desktop).

Necessary redirection example:

Current URL: http://oldsite.com/WS/WSInfo/WSDataClient

URL redirection: http://web1.site.com/WS/WSInfo/WSDataClient

I must perform several redirects (so I have to repeat the rule many times), I can not redirect all "olsite.com" to "web1.site.com", since both balancers will have concurrent calls, not all services, "http://oldsite.com" will stop being used.

The rule of HAProxy:

###----SERV_WSInfo_WSDataClient_test
acl withwsdl_SERV_WSInfo_WSDataClient url /WS/WSInfo/WSDataClient_test?wsdl
acl notwsdl_SERV_WSInfo_WSDataClient path_beg  /WS/WSInfo/WSDataClient_test 

http-request redirect location http://web1.site.com/WS/WSInfo/WSDataClient?%[query] code 301 if withwsdl_SERV_WSInfo_WSDataClient  
http-request redirect location http://web1.site.com/WS/WSInfo/WSDataClient code 301 if notwsdl_SERV_WSInfo_WSDataClient

This works in the Flex applications that consume it, but not in the .Net point, I have been able to detect that:

Flex calls WSDL twice from the service (I suspect that by the redirect of the rule), but it works. .Net, on the other hand, never asks for the WSDL and the service returns error, blank response.

  1. Someone can recommend how would be the correct way to implement the rule to achieve the necessary redirection.
  2. To redirect an HTTPS with that same URL, should I add more logic?

  3. They think that I'm not using the necessary tool to do it, they can recommend another one (currently HAProxy is used but if I manage to make it work in another Proxy, I could ask to evaluate).

I thank you for your help since I do not use the tool and I am not from the network area.

Upvotes: 0

Views: 7971

Answers (1)

Nico
Nico

Reputation: 12683

Given they are both on different HAProxy servers makes it a bit easier as you dont need to worry about an acl for the new domain. Here is a simple acl that doesnt worry about the querystring at all.

acl is_SERV_TEST url_beg -i /WS/WSInfo/WSDataClient

This acl checks the beginning of the url (case insensitive with the -i) against our url we need to redirec the prefix (host).

http-request redirect code 301 prefix http://web1.site.com if is_SERV_TEST

The redirection simply changes the prefix and maintains the remainder of the URL. For this reason we dont need to worry about the query string etc.

Full Code

acl     is_SERV_TEST url_beg -i /WS/WSInfo/WSDataClient
http-request redirect code 301  prefix http://web1.site.com if is_SERV_TEST

SSL Question

For SSL related rewrites this is a double edge sword, and this is against the requirement of the company. For example if you want all request from http://oldsite.com to go to the SSL (HTTPS) url for web1.site.com then you should be doing that in your 301 redirect.

So you would simply change the rewrite prefix to https://web1.site.com.

Finally if you also need to mange the 301 redirect for ssl (ie over port 443) you should create another listener frontend binding to :443 and use the same rules as your port :80 listener.

Upvotes: 1

Related Questions