Forum Discussion
French_Poul_307
Nimbostratus
Jun 10, 2010iRules for reverse proxy
Hello,
First, I'm sorry for my english ; I'm french and I talk a very bad english...
I'm new with BigIP and with iRules, so I have some difficulties to do what I want... :-(
I have a BigIP 6900, and I try to use it like a load balancer (normal!) but like a reverse proxy too... I have understand that I must use iRules, but I would like to know what iRules I must use to select the http requests which are good (no errors, crc ok, ...) ?
I have read the wiki of iRules, but I don't find a solution...
Thank you in adavance for your help!
11 Replies
- Michael_Yates
Nimbostratus
Your request for information is is pretty broad, but I will give you an example. You must decide what is good traffic in order to route it to a specific pool of servers, and what to do with the rest of the traffic (whether it is bad or doesn't meet any of the criteria set earlier in the iRule).
Here is an example. You have one website that contains conent for three different languages:
http://www.website.com/english
http://www.website.com/french
http://www.website.com/german
You divide your web servers into different pools that host a certain language, and now you must route the traffic to each set of servers depending on the URI.
[HTTP::host] = www.website.com
[HTTP::uri] = /english, /french, or /german
You would place this iRule on the Virtual Server:when HTTP_REQUEST { switch -glob [string tolower[HTTP::uri]] { "/english*" { pool pool.for.english } "/french*" { pool pool.for.french } "/german*" { pool pool.for.german } default { HTTP::redirect http://[getfield [HTTP::host] ":" 1]/english } } }
Is this the type of information you were looking for? - French_Poul_307
Nimbostratus
Since yesterday, I have learned some information about the bigIP, and it's true, my question is broad...!
Yes, it's the type of information I am looking for. I would like to have some simple samples for understand what I can do with it.
What "switch -glob [string tolower[HTTP::uri]]" do ? in particular "[string tolower[HTTP::uri]]" ? I know what is a string and an uri, but what do tolower...? string [HTTP::uri] doesn't work? - Michael_Yates
Nimbostratus
If these were the possible URL's tied to a Virtual Server:
http://www.website.com/english
http://www.website.com/french
http://www.website.com/german
These would be the values of the [HTTP::host] and [HTTP::uri] values:
[HTTP::host] = www.website.com
[HTTP::uri] = /english, /french, or /german
string tolower [HTTP::uri] takes the value of the [HTTP::uri] and forces all upper case characters to lower case (basically putting them into a "known" format for comparison). Example:
/ENGLISH would be converted to /english
/English would be converted to /english
switch -glob is a string compare of the specified value.
Example. If the incoming URL was this:
http://www.website.com/ENGLISH
The /ENGLISH would be forced to lower case (/english) and then compared for a match to the provided vaules:
"/english*" { pool pool.for.english }
"/french*" { pool pool.for.french }
"/german*" { pool pool.for.german }
If a match is found then it will take whatever action is specified in the { } for that match. In this case it will send the traffic to a pool of server named "pool.for.english".
Hope this helps. - French_Poul_307
Nimbostratus
Hope this helps.
Yes, thanks!
But I don't understand why when I try this :
when HTTP_REQUEST {
if { not ([HTTP::uri] equals "/french/") } {
HTTP::redirect /french/
}
}
it's ok, and when i try :
when HTTP_REQUEST {
if { not ([HTTP::uri] equals "/french/") } {
[HTTP::uri] /french/
}
}
it's not ok. - Michael_Yates
Nimbostratus
HTTP::redirect is a full 302 redirect, so you have to provide it the entire URL.
Try this:when HTTP_REQUEST { if { not ([HTTP::uri] equals "/french/") } { HTTP::redirect "http://[getfield [HTTP::host] ":" 1]/french/" } }
The second example you gave doesn't actually change anything. It reads and compares the [HTTP::uri] and if it equals "/french" then your telling it to change the [HTTP::uri] to "/french/".
If you told hit to change it to "/english/" then it would change the request sent to the server, but not change what was displayed in the browser.
The browser would show:
http://www.website.com/french/
The server would see:
http://www.website.com/english/
You would use this if you wanted to simplify the vanity URL, but actually had your website code arranged differently. - French_Poul_307
Nimbostratus
Ok, your solution works.
But I try to understand the difference between http::uri and http::redirect...
Can you explain me this : HTTP::redirect "http://[getfield [HTTP::host] ":" 1]/french/"
I suppose you do this for putting /french/ on the uri. But, why ":" 1]/french/" ?
Another question :
When I do :
when HTTP_REQUEST {
if { not ([HTTP::uri] equals "/cacti/") } {
[HTTP::uri] "/cacti/"
}
}
Why I obtain a white page on the web browser with (traducted into english by me!!) :ERROR The URL asked can't be loaded Trying to load the URL : http://xxx.xxx.xxx.xxx/english This error was meet : Error of reading The system returned : (104) Connection reset by peer One error is being trying to acceed to the network.
Thank you for your help! - The_Bhattman
Nimbostratus
Hi French,
The ":" basically strips out any port info. For example if the http request was for www.domain.com:456/French.
In regards to the /cacti your code it might work if you do the following:
[HTTP:uri] /cacti/[HTTP:uri]
I hope this helps
Bhattman - The_Bhattman
Nimbostratus
Hi French,
The ":" basically strips out any port info. For example if the http request was for www.domain.com:456/French.
In regards to the /cacti your code it might work if you do the following:
[HTTP:uri] /cacti/[HTTP:uri]
I hope this helps
Bhattman - hoolio
Cirrostratus
The square braces act like backticks to execute a command. So if you want to retrieve the value for the URI, you would use [HTTP:uri]. If you want to set the URI you would not want to use the square braces: HTTP:uri "/cacti/[HTTP:uri]"
Aaron - French_Poul_307
Nimbostratus
Ok! Thanks Bhattman and hoolio, it's more clear for me!
If I have another question like this, must I open a new topic or can I use the same ?
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects