Forum Discussion
Newbie mantenance page based on IP address
what i want to do for our maintenance page that redirects all except a certain IP address specified to a site down page.
so something like this only IP address 10.10.x.x , 142.x.x.x , 172.x.x.x are allowed to access the real site such as /prod/x
all other requests get sent to a redirection URL at /prod/maint/x
ive tried some examples it gets confusing for me when the IP addresses get thrown in.
Thanks alot.
11 Replies
- Chris_Miller
Altostratus
I like using data groups for this. You can configure an "address-type data group" from the GUI via "Local Traffic" -> "iRules" -> "Data Groups"
Once your data group exists, you can write an iRule fairly easily. What version are you running? - Deekdeek_103899
Nimbostratus
Hi that sounds great, im running 9.4.8 if you could step by step it for me that would be great as i don't have a great understanding at this point.
thanks. - Chris_Miller
Altostratus
Did you create the datagroup yet? It's pretty self-explanatory once you get to the data groups section via my instructions above.
From there, let's say you made a data group called "maintenance_addresses." Your iRule would look similar to below:when HTTP_REQUEST { if { ![matchclass [IP::client_addr] eq maintenance_addresses] } { HTTP::redirect "http://www.sample.com/maintenancepage.html" } }
For a step-by-step on the rule:
1. First, we're doing this from the HTTP_REQUEST event. That event is triggered as soon as the user makes an HTTP Request.
2. We're using "matchclass" to see whether the data group you created contains the user's IP address. Since we want to redirect users whose IPs aren't in the data group, we're using the "!" symbol to basically say "if their address isn't in the data group."
3. If their address wasn't in the data group, we redirect them to the maintenance page. - Deekdeek_103899
Nimbostratus
Thanks for your quick responses, i will try this first thing in the AM and let you know how i fair out.
Thanks again! - Deekdeek_103899
Nimbostratus
Great stuff i made some little changes but this seems to work. Now i wanted to add 400,500 error redirects to this, should i incorporate into the same irule ? how would i include those?when HTTP_REQUEST {
if { ![matchclass [IP::client_addr] eq M_Page] } {
if { not ([string tolower [HTTP::uri]] starts_with "/imageserver") } {
HTTP::redirect "https://xxx.xxxx.xxx/imageserver/ServiceUnavailable.html"
}
}
}
- Chris_Miller
Altostratus
You can certainly add to the same iRule, yes. Are you basically trying to send the user to a specific page if LTM detects an error code response from a pool member? - Deekdeek_103899
Nimbostratus
yes for instance if received 404, 403, 500 then again redirect to maintenance page. - Chris_Miller
Altostratus
Simple enough, just use the "HTTP::status" command.
http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__status.html
Something like this would work. This is simply a different iRule "event" and can be inserted at the end of your current iRule.when HTTP_RESPONSE { switch -glob [HTTP::status] { "403" - "404" - "500" { HTTP::redirect "http://www.sample.com/maintenance.html" } } }
I've never used HTTP::redirect from the response event and I'm a bit confused that it's usable from there but give it a shot. If it doesn't work, use the rule below instead:when HTTP_RESPONSE { switch -glob [HTTP::status] { "403" - "404" - "500" { HTTP::respond 302 Location "http://www.sample.com/maintenance.html" } } } - Deekdeek_103899
Nimbostratus
First one seems to work like a charm!
thx again. - hoolio
Cirrostratus
Nice work, Chris.
You can also do this with the fallback host and the 'Fallback on Error Codes' fields on a custom HTTP profile.
Aaron
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
