Rewrite rule forward to specific domain and port

Hello Guys/Gals -- I’m new to irules and am trying to figure out a re-write scenario, I’m trying to change a current rule that does a redirect, and change it to rewrite. The current rule is like this, it works but of course the browser url gets updated and we want to keep the destination from displaying.

=================================================================================================== when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with “abc-news.east.foo.com” } { HTTP::redirect “https://server.nbc-news.west.foo.com:7012/Portal/index.html” } } ===================================================================================================

I Attempted the following re-writes but browser hangs. I’m trying to forward to a specific domain and server that is listening on a specific port.

when HTTP_REQUEST { if { ([HTTP::host] eq “abc-news.east.foo.com”) && ([HTTP::uri] eq “” } { HTTP::header replace “Host” “https://server.nbc-news.west.foo.com:7012” HTTP::uri “/Portal/index.html” } }

================================================================================

when HTTP_REQUEST { if { ([HTTP::host] eq “abc-news.east.foo.com”)} { HTTP::header replace “Host” “https://server.nbc-news.west.foo.com:7012”} { HTTP::uri “/Portal/index.html” } }

Wondering if I might need to use a pool member to redirect, so I created a pool that has it service port going to 7012. It appears to be listening OK as it green. So my question is how can I rewrite to go to that pool or am I going about this the wring way. I’m not finding much about rewrite using a port.

Thanks

T

I don’t think you need to do anything with the URI and the host doesn’t need the https:// in it. I don’t think you need the 7012 in the header either. You’re pool members can be listening on any port you want as long as you configure LTM appropriately.

Keep in mind that absolute links (if any) in responses will contain the ‘original’ hostname.’

You shouldn’t need to specify the port unless the application requires it. It’s rare but some do. So instead of redirecting on host, you want to silently modify the host header for ingress traffic. You’ll definitely need a pool with port 7012 members and modify the host header on every request. The URI change from “/” to “/Portal/index.html” should probably be a redirect though - unless you want to be in the business of managing every possible URI (the work of a rewrite proxy).

when HTTP_REQUEST {
     if { [HTTP::uri] equals "/" } { 
          HTTP::redirect "/Portal/index.html"
     } else {
          HTTP::header replace Host "server.nbc-news.west.foo.com"
     }
}

Again, should you need to completely hide the URI as well, you can use the HTTP::uri command on the ingress, but you have to be mindful of any possible URI translations.

thx--tried removing the https:// but still not working.

i assume foo is pool of server.nbc-news.west.foo.com and it is running http on port 7012.

e.g.

[root@ve10:Active] config  b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.19.79:443
   ip protocol 6
   rules myrule
   profiles {
      clientssl {
         clientside
      }
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b pool foo list
pool foo {
   members 200.200.200.101:7012 {}
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   if {[HTTP::uri] equals "/"} {
      HTTP::uri "/Portal/index.html"
   }
   HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}
}

[root@ve10:Active] config  ssldump -Aed -nni 0.0 port 443 or port 7012 -k /config/ssl/ssl.key/default.key
New TCP connection 1: 172.28.19.251(44761) <-> 172.28.19.79(443)
1 1  1349110332.3796 (0.0101)  C>S SSLv2 compatible client hello
1 2  1349110332.3797 (0.0000)  S>CV3.1(81)  Handshake
1 3  1349110332.3797 (0.0000)  S>CV3.1(953)  Handshake
1 4  1349110332.3797 (0.0000)  S>CV3.1(4)  Handshake
1 5  1349110332.3817 (0.0020)  C>SV3.1(262)  Handshake
1 6  1349110332.3817 (0.0000)  C>SV3.1(1)  ChangeCipherSpec
1 7  1349110332.3817 (0.0000)  C>SV3.1(36)  Handshake
1 8  1349110332.3970 (0.0152)  S>CV3.1(1)  ChangeCipherSpec
1 9  1349110332.3970 (0.0000)  S>CV3.1(36)  Handshake
1 10 1349110332.3986 (0.0015)  C>SV3.1(184)  application_data
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Accept: */*
    Host: abc-news.east.foo.com

    ---------------------------------------------------------------
New TCP connection 2: 200.200.200.10(44761) <-> 200.200.200.101(7012)
1349110332.4007 (0.0009)  C>S
---------------------------------------------------------------
HEAD /Portal/index.html HTTP/1.1
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: server.nbc-news.west.foo.com:7012

---------------------------------------------------------------

Note, as shown in the examples by tvotta and nitass you should remove the quotes around Host. Also, please check there is a space before and after each } or {. You also need to remove the ( and ).

Thx- -

To reach this app the port is needed as there are other app on the same box. Pretty sure the port needs to be specified at some place.

I attempted your suggestion as it did make sence to me but am not getting there.

Not sure if I am explaining correctly.

Thes destination is a server running an app on a specific port. I’m trying to rewirite to that destination.

https://server.nbc-news.west.foo.com:7012/Portal/index.html

Is there a method to use irules to forward to a pool where I have the member set up at the service port I need?

thx

It doesn’t matter what port the server is listening on, LTM is acting as a proxy so your Virtual Server can be on port 443 and your pool member listening on 7012 and it all just works; the client connection is terminated on 443 and a new connection is created from the F5 to the pool member on 7012. No need to use an iRule to change the port, it’s automatic. You could have six pool members all listening on different Service Ports and it wouldn’t matter, it would work.

https://server.nbc-news.west.foo.com:7012/Portal/index.html

is this also virtual server on bigip? if so, would you mind posting virtual server and pool configuration?

b virtual (virtual server name) list

b pool (pool name) list

nitass - -

foo is not a pool it’s just part of the fqdn.

I added the pool with the member’s server port of 7012

b virtual vs_portal-https

p poo p_portal_7012l

now trying to figure out how to get a irule to use it.

sorry to confuse. can you post these command output?

b virtual (abc-news.east.foo.com) list

b virtual (server.nbc-news.west.foo.com) list

b pool (server.nbc-news.west.foo.com) list

I dont have acces to the BIG-IP CLI:

b virtual (abc-news.east.foo.com) list

This is an existing IP that resolves as abc-news.east.foo.com. This is set up as a VS and the current working irule is associated to it, but no pool are associated with this.

b virtual (server.nbc-news.west.foo.com) list

This is a backend server that is running an app listening for request at port 7012

b pool (server.nbc-news.west.foo.com) list

This does not exist

can you try this?

1. create new pool (e.g. foo) containing server.nbc-news.west.foo.com runing on port 7012

2. modify abc-news.east.foo.com virtual server similar to the following configuration

[root@ve10:Active] config  b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.19.79:443
   ip protocol 6
   rules myrule
   profiles {
      clientssl {
         clientside
      }
      http {}
      serverssl {
         serverside
      }
      tcp {}
   }
}
[root@ve10:Active] config  b pool foo list
pool foo {
   members 200.200.200.101:7012 {}
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   if {[HTTP::uri] equals "/"} {
      HTTP::uri "/Portal/index.html"
   }
   HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}
}

Have gotten it to redirect however the app is not starting as it previously did.

Set up the pool with service port 7012 member is the app server

Assigned the VS to use the pool

Have tried various iterations of this rule:

rule myrule {

when HTTP_REQUEST {

if {[HTTP::uri] equals “/”} {

HTTP::uri “/Portal/index.html”

}

HTTP::header replace Host “server.nbc-news.west.foo.com:7012”

}

}

Need to figure out how get the app to run properly.

thx

I’d probably throw in some logs at this point. The app may be doing things you didn’t expect.

when HTTP_REQUEST {
     log local0. "uri = [HTTP::uri]"
    if { [HTTP::uri] equals "/" } {
        log local0. "changing uri to /Portal/index.html"
        HTTP::uri "/Portal/index.html"
    }
    log local0. "incoming host header = [HTTP::header Host]"
    HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}

Then if you can, capture on the server side to see what it’s sending and receiving.

if you map abc-news.east.foo.com to server.nbc-news.west.foo.com IP address in local hosts file (i.e. \windows\system32\drivers\etc\hosts) and access https://abc-news.east.foo.com:7012/Portal/index.html, does it work?

i have a an alias in dns to handle that translation and that appears to be working.

I added the log statements (thanks for that) and it appears that the header is not getting re-written. the log reports this:

Oct 2 15:26:17 local/tmm3 info tmm3[5303]: Rule portral-dev : changing uri to /Portal/index.html

Oct 2 15:26:17 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 15:26:17 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 15:26:17 local/tmm1 info tmm1[5301]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 15:26:17 local/tmm2 info tmm2[5302]: Rule portral-dev : incoming host header = abc-news.east.foo.com

abc-news.east.foo.com this does not seem to be getting re-written to server.nbc-news.west.foo.com:7012

I’m using this rule:

when HTTP_REQUEST {

log local0. “uri = [HTTP::uri]”

if { [HTTP::uri] equals “/” } {

log local0. “changing uri to /Portal/index.html”

HTTP::uri “/Portal/index.html”

}

log local0. “incoming host header = [HTTP::header Host]”

HTTP::header replace Host “server.nbc-news.west.foo.com:7012”

}

Any Ideas ? Thought that the “header replace Host” would do it but it seem like it’s not

You are logging before the header replacement! You need to add another log statement after the header is replaced.

Thanks !

I added a statement

log local0. “host header after header replace = [HTTP::header Host]” after the HTTP:: header replace, but unfortunately still the header is not getting rewritten.

Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : changing uri to /Portal/index.html

Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : host header after header replace = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm info tmm[5299]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm info tmm[5299]: Rule portral-dev : host header after header replace = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm3 info tmm3[5303]: Rule portral-dev : host header after header replace = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm2 info tmm2[5302]: Rule portral-dev : incoming host header = abc-news.east.foo.com

Oct 2 17:20:49 local/tmm2 info tmm2[5302]: Rule portral-dev : host header after header replace = abc-news.east.foo.com

Must be another method to get this header to re-write.

Can you try this with additional debug logging? I assume you’re on a pre-v11.0 release which had caching of many of the HTTP:: command values in the same iRule event.

when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
if { [HTTP::uri] equals "/" } {
log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting / to /Portal/index.html"
HTTP::uri "/Portal/index.html"
}
HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}
when HTTP_REQUEST priority 501 {

 Debug logging only--remove or comment out this event once testing is complete
log local0. "[IP::client_addr]:[TCP::client_port]: Updated host/uri: [HTTP::host][HTTP::uri]
}
when HTTP_RESPONSE {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::status] response from [LB::server]. Redirect location: [HTTP::header location]"
}

Aaron