ProxyPass - Reverse Proxy / Backend URL rewrite.

I have been trying to allow a user to type (for example) www.google.com in their browser, that then is sent to a virtual server on the LTM that sends the request to www.yahoo.com. The user sees the content of www.yahoo.com but their browser still shows www.google.com. So far I have had no luck in getting this going. I have looked at a number of iRules and not found one that meets my needs. ProxyPass seems to be the closest but I can not get it to work. I am a network guy and not a programmer so maybe I just don’t get the iRule logic. Can anyone help me? The LTM needs to send traffic to that URL and resolve it via DNS as the site could change.

note, the URL is really more like what the user types: service.mycompany.com and it needs to redirect to externalsite.longurl.application.service.othercompany.com. Will need the LTM to change it on the way back too.

Sounds like you’re rewriting the URI, but you want an HTTP redirect. You just need to create an iRule and assign it to the virtual in questions. Something like this:

when HTTP_REQUEST {
if {[string tolower [HTTP::host]] starts_with "service.mycompany.com" } {
HTTP::redirect http://externalsite.longurl.application.service.othercompany.com[HTTP::uri]
}
}

-George

Posted By watkins on 08/30/2010 04:04 PM

Sounds like you’re rewriting the URI, but you want an HTTP redirect. You just need to create an iRule and assign it to the virtual in questions. Something like this:

when HTTP_REQUEST {
if {[string tolower [HTTP::host]] starts_with "service.mycompany.com" } {
HTTP::redirect http://externalsite.longurl.application.service.othercompany.com[HTTP::uri]
}
}

-George

And this is where I got confused…he mentioned a user being able to see www.yahoo.com in their browser while their traffic was sent to www.google.com It’s like a host-header re-write for outbound traffic üòõ

Thanks George but this really does not accomplish what I am being asked to do. This does a successful redirect but shows to the user as a redirect. I need that to be hidden. That is the first step. Once I get that working I need the F5 to change all links presented on the page to the customer URL from provider URL. We basically need an external site from a 3rd party provider to appear as an internal web site.

Steve…it’s easy enough to rewrite the host or URI between LTM and the server…but are you basically trying to do that for outbound traffic?

Perhaps if you could outline the traffic flow you desire, it might be easier.

Chris, What I am waiting to do is have users go to www.internal-url.com and get content from www.external-url.com. The traffic flow is Client types internal-url --> LTM --> external-url. Return traffic: external-url --> LTM --> client (and appears as intenral-url) I recognize this is an odd request and I may be getting terms wrong so I apologies for that.

Thanks for clearing that up Steve.

Why not simply do a DNS CNAME for this?

In order to get your traffic externally, you’re going to need DNS’s help, so merely changing the host header isn’t necessarily going to help us here. Simply doing a DNS CNAME might though.

So, you’d simply need to create an Alias/CNAME for “www” in the internal-url.com DNS zone that pointed to “www.external-url.com”

This make sense?

Hi Steve,

What are you asking won’t be accomplished without the iRules so I want to apologize upfront but I am going to start throwing you up some iRule code. It sounds like you don’t want re-write but you basically want a webproxy

Here is a piece of untested code

However, there are some items you will need to address before hand.

- The ADC must have access to internet

- You must make sure that you have configured the ADC for DNS local lookup as described in SOL5299 located in ask.f5.com (Don’t ask me how I remember this stuff :slightly_smiling_face: )

Obviously this is a simple example but my hope at the very least is that it generates ideas in this discussion.

when HTTP_REQUESTED {

    if { [HTTP::host] eq "www.yahoo" } {
          NAME::lookup www.google.com
         Wait until name resolution is completed before sending you to the new page  
        HTTP::collect
        }
}

when NAME_RESOLVED {
   set response [NAME::response]
   resolved www.google.com to an ip address via load balancer and now use that in the node command.
 
  switch [llength $response] {
      0 {
          HTTP::respond 500 content "Couldn't Process Request}
      default {
             HTTP::uri "[HTTP::uri]"
              HTTP::header replace "Host" "www.google.com"
             node [llindex $response 0] 80
          }
   }
HTTP::release
}

I hope this helps

Bhattman

I did ask first why we could not use DNS as you mention but was told the reason is the web page services up links that are hard coded to the external URL. Plus it also sends back a cookie with the external URL. It all needs to be modified before returning it to the client, that is where the LTM comes in.

Sounds like you simply need to point to the website and do some URL rewriting. Cookie can also be adjusted as well

Are the links different or the same?

Bhattman

The functionality you are looking for is in the well documented proxypass iRule.

http://devcentral.f5.com/wiki/default.aspx/iRules/ProxyPass.html Click Here

The external and internal URL are different of course but each of those will remain the same.

Posted By Jason Rahm on 08/31/2010 09:52 AM

The functionality you are looking for is in the well documented proxypass iRule.

http://devcentral.f5.com/wiki/default.aspx/iRules/ProxyPass.html Click Here

As mentioned that is where I started but I could not get it to work. If that sounds like the correct iRule for what I need I will revisit it again.

Hi Steve,

If you decide to use the Proxypass and get stuck on something go ahead and use this forum to post your issue.

Thanks,

Bhattman

Ok, I took a few days to move it back to proxypass and still can not get it to work. I have PoxyPass set to log and I see the log message but it alway just sends it to the pool I had to define and not to the website configured in my external file. Any tips on where I should look to resolve this?

Logs. Changed a few things to mask a few items, VS=XYZ.

You can see it’s hitting the iRule just not redirecting to the external url, just sending it to the pool I had to define.

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : XYZ: 10.64.2.18:62832 → 10.64.196.100:80

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Found Rule, Client Host=brqa010.internalurl.com, Client Path=/, Server Host=web1qa.spsenet.externalurl.com, Server Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: New Host=web1qa.spsenet.externalurl.com, New Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Using default pool TEST_pool

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Removed Accept-Encoding header

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: $stream_expression_cmd: STREAM::expression “@web1qa.spsenet.externalurl.com/@brqa010.internalurl.com/@”, $stream_enable_cmd: STREAM::enable

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Successfully configured and enabled stream filter

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Found Rule, Client Host=brqa010.internalurl.com, Client Path=/, Server Host=web1qa.spsenet.externalurl.com, Server Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: New Host=web1qa.spsenet.externalurl.com, New Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Using default pool TEST_pool

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Removed Accept-Encoding header

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: $stream_expression_cmd: STREAM::expression “@web1qa.spsenet.externalurl.com/@brqa010.internalurl.com/@”, $stream_enable_cmd: STREAM::enable

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Successfully configured and enabled stream filter

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Found Rule, Client Host=brqa010.internalurl.com, Client Path=/, Server Host=web1qa.spsenet.externalurl.com, Server Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: New Host=web1qa.spsenet.externalurl.com, New Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Using default pool TEST_pool

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Removed Accept-Encoding header

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: $stream_expression_cmd: STREAM::expression “@web1qa.spsenet.externalurl.com/@brqa010.internalurl.com/@”, $stream_enable_cmd: STREAM::enable

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/: Successfully configured and enabled stream filter

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: Found Rule, Client Host=brqa010.internalurl.com, Client Path=/, Server Host=web1qa.spsenet.externalurl.com, Server Path=/

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: New Host=web1qa.spsenet.externalurl.com, New Path=/favicon.ico

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: Using default pool TEST_pool

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: Removed Accept-Encoding header

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: $stream_expression_cmd: STREAM::expression “@web1qa.spsenet.externalurl.com/@brqa010.internalurl.com/@”, $stream_enable_cmd: STREAM::enable

Wed Sep 8 14:21:00 CDT 2010 info local/tmm tmm[5142] Rule ProxyPass : VS=XYZ, Host=brqa010.internalurl.com, URI=/favicon.ico: Successfully configured and enabled stream filter

did you ever get this to work? i’m having the same issue; the rule goes off but still sends my traffic to the default pool.

Add me to this list… Aaron gave me some suggestion for this but still not complete solution. Any luck for you guys ??

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1179347/showtab/groupforums/Default.aspx

i wasn’t able to get anything working properly. we have a serveriron load balancer that does this natively, i’m disappointed that f5 hasn’t implemented that same sort of functionality.

Raj, I replied to your thread.

Nik, which LTM version are you running? Which version of the ProxyPass iRule are you testing? Can you post the config datagroup ‘b class CLASS_NAME list’, the debug logs from the iRule and a description of the failure?

Aaron