Jump to content
Welcome to our new Citrix community!

Url rewrite with content switching


Patrick Brunmayr

Recommended Posts

Hello 

 

I guess my question is quite simple still i am stuck on how to do it.

 

I want to load balance traffic on my host api.mydomain.com where the first part of the path starts with /docs to a predefined

number of web servers running on other machines.

 

My services are running on

 

http://192.168.20.1:8080

http://192.168.20.2:8080

 

Main challenge

 

I need to rewrite the url so that everything that comes after /docs/<stuff>/<more-stoff> should be seeny by my service as /<stuff>/<more-stuff>

 

Example

 

The request https://api.mydomain.com/docs/myapi should be load balanced to the services as

 

http://192.168.20.1:8080/myapi

http://192.168.20.2:8080/myapi

 

Link to comment
Share on other sites

You can do responder (to redirect) or rewrite.

Start with the basic rewrite first and then you can figure out lb or cs as needed.

I'm assuming request time rewrites and not worrying about links in return responses.

 

Rewrite Action:  (there are multiple ways to change the path)

REPLACE

Target:  http.req.url.path

Expression (text to replace path with):  http.req.url.path.set_text_mode(ignorecase).after_string("/docs")

 

Rewrite Policy:

Trigger when the url path starts_with("/docs")

http.req.ur.path.set_text_mode(ignorecase).starts_with("/docs")

 

This will result in the origin:  /docs/<stuff>/<more-stuff> being rewritting to "/<stuff>/<more-stuff>"  Preserving any other path/query parameter elments after "/doc"

 

Next:

The load balancing config should handle the service and ports selection.  The rewrite should not need to handle that.

 

Though a full URL rewrite can be done instead of just a path rewrite; but didn't want to embed "service" names. the lb fqdn can be specified; but rewrite can't rewrite host fqdn for the destination services as the REWRITE decision is made before the destination service is made.

Link to comment
Share on other sites

Thank you for your reply. :5_smiley:

 

Everything is clear to me except the last part. Could you provide an example? What about the host fqdn?

 

4 hours ago, Rhonda Rowland1709152125 said:

Though a full URL rewrite can be done instead of just a path rewrite; but didn't want to embed "service" names. the lb fqdn can be specified; but rewrite can't rewrite host fqdn for the destination services as the REWRITE decision is made before the destination service is made.

Link to comment
Share on other sites

Do you actually need the host to be changed? If so, we can't really do it the way you are trying.

 

Usually when load balancing a user goes to https://lbfqdn.demo.com/<pathandquery>

Load balancing then selects the destination service.

 

In most cases, but not all, the user request all requires the FQDN of the lb vserver (client side entity) and the traffic is still sent to the destination of the service without the need to rewrite the host header. destination and port is determined by the service itself.

 

See if this helps clarify:

If you need the user to make a new request to a new location you would use RESPONDER to redirect the user.

If you want the user to make the original client request to "x" and then you fetch "y" server side, then you use rewrite.  The rewrite will fetch the new path, the lb decision gets it to the service destination.

But I can't use a rewrite policy to insert the fqdn of the service destination in the rewritten request...because the lb decision hasn't been made at the time the rewrite is performed.

 

I would try the REWRITE first with the regular load balancing config (i know you services are on different ports, don't know if the lb vserver is or is not).

add service svc1 192.168.20.1 http 8080

add service svc2 192.168.20.2 http 8080

add lb vserver lb_vsrv_demo http <VIP1> 80   # or adjust port

bind lb vserver lb_vsrv_demo svc1

bind lb vserver lb_vsrv_demo svc2

# later bind policy to vserverd...

 

Without the rewrite (just doing regular load balancing), a request to http://<lbfqdn>/path/stuff

Will result in will go to 192.168.20.1:8080 or 192.168.20.2:8080 by virtue of the load balancing for the original /path/stuff requested without a rewrite to host fqdn or port being needed. Load balancing gets it to the destination because these are the services that are bound.

 

Usually, when we the rewrite requests in this scenario, we only have to rewrite the path/query portions and not the hostname:port as it is handled by the load balancing decision.

 

IF the backend App has to see service specific hostname and port as part of the request, then things get tricky.   And the approach might have to be rethought.

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...