Forum Discussion
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
21 Replies
- tvotta_94824
Nimbostratus
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 - nitass
Employee
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" } } - tvotta_94824
Nimbostratus
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 - Kevin_Stewart
Employee
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. - nitass
Employee
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? - tvotta_94824
Nimbostratus
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 - What_Lies_Bene1
Cirrostratus
You are logging before the header replacement! You need to add another log statement after the header is replaced. - tvotta_94824
Nimbostratus
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. - hoolio
Cirrostratus
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 - tvotta_94824
Nimbostratus
Great help!
I added as you mention and I'm getting logs - -
I also added a pool that has one member that uses the service port 7012 that I need and attached the pool to the virtual server.
Now i get the initial screen of the app but appears that I may need to add some additional re-writes or programmaticly re-write all headers.
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: GET to abc-news.east.foo.com/
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: Rewriting / to /Portal/index.html
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: Updated host/uri: server.nbc-news.west.foo.com:7012/caelaPortal/CAELA/index.html
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: 304 response from p_caela_portal_7012 10.xxx.xx.xx 7012. Redirect location:
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: GET to abc-news.east.foo.com/js/jquery.tools.min.js
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: Updated host/uri: server.nbc-news.west.foo.com:7012/js/jquery.tools.min.js
Oct 2 20:06:56 local/tmm info tmm[5299]: Rule portral-dev : 172.24.xx.xx:57203: 404 response from p_caela_portal_7012 10.xxx.xx.xx 7012. Redirect location:
Oct 2 20:06:56 local/tmm2 info tmm2[5302]: Rule portral-dev : 172.24.xx.xx:57205: GET to abc-news.east.foo.com/images/nav_images.png
Oct 2 20:06:56 local/tmm2 info tmm2[5302]: Rule portral-dev : 172.24.xx.xx:57205: Updated host/uri: server.nbc-news.west.foo.com:7012/images/nav_images.png
Oct 2 20:06:56 local/tmm3 info tmm3[5303]: Rule portral-dev : 172.24.xx.xx:57204: GET to abc-news.east.foo.com/images/logo_large.png
Oct 2 20:06:56 local/tmm3 info tmm3[5303]: Rule portral-dev : 172.24.xx.xx:57204: Updated host/uri: server.nbc-news.west.foo.com:7012/images/logo_large.png
Oct 2 20:06:56 local/tmm2 info tmm2[5302]: Rule portral-dev : 172.24.xx.xx:57205: 404 response from p_caela_portal_7012 10.253.90.66 7012. Redirect location:
Oct 2 20:06:56 local/tmm3 info tmm3[5303]: Rule portral-dev : 172.24.xx.xx:57204: 404 response from p_caela_portal_7012 10.253.90.66 7012. Redirect location:
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
