F5 iRules 配置翻译F5配置:when HTTP_REQUEST { if { [HTTP::host] eq
  

俞健 42241人觉得有帮助

{{ttag.title}}
本帖最后由 俞健 于 2023-8-17 16:48 编辑

F5 iRules 配置翻译

F5配置:
when HTTP_REQUEST {
    if { [HTTP::host] equals "hqbz.shufe.edu.cn" } {
        HTTP::redirect "https://hqbz.sufe.edu.cn[HTTP::uri]"
    }
    elseif { [HTTP::uri] starts_with "/hqcy/" } {
        if { [ active_members pool_hqcy_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_hqcy_rs
        }
    }
    elseif { [HTTP::uri] starts_with "/place/" } {
        if { [ active_members pool_place_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_place_rs
        }
    }
    elseif { [HTTP::uri] starts_with "/saf/" } {
        if { [ active_members pool_security_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_security_rs
        }
    }
    elseif { [HTTP::uri] starts_with "/zc/" } {
        if { [ active_members pool_gcms_rs ] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_gcms_rs
        }
    }
    elseif { ([HTTP::uri] starts_with "/health/")} {
        if { [ active_members pool_healthcare_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_healthcare_rs
        }
    }
    elseif { ([HTTP::uri] starts_with "/mss/")} {
        if { [ active_members pool_mss_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_mss_rs
        }
    }
    else {
        if { [ active_members pool_newstu_rs] < 1 } {
            HTTP::respond 200 content [ifile get operation_page.html] "Content-Type" "text/html"
        }
        else {
            pool pool_newstu_rs
        }
    }
}


ad ipro配置:
local debug = false

--判断节点池里面的可用节点数量
local function active_members(poolname)
        local nodes = nodelist(poolname)
        return table.maxn(nodes)
end

local function string_contains(s,p)  
        local i,j = string.find(s,p)
        if i then
                return true
        else
                return false
        end
end


event HTTP_REQUEST {
        
    local Host = HTTP.header("Host")
        local uri = HTTP.uri()
        local reply_page = Object.get(Object.page, "operation_page.html")  --资源管理,自定义内容里面定义,200 OK是名称。
        local reply_page_1 = Object.get(Object.page, "limit_xiaonei_long_term.html")
        local srcip = HTTP.remoteaddr() --获取客户端地址
        local ipset = Object.get(Object.address, "sufe_ip_list") --获取管理员地址集
    if table.getn(Host) ~= 1 then
            HTTP.close()
                return
    end
    Host = Host[1]

        if Host == "hqbz.shufe.edu.cn" then
                HTTP.redirect("https://hqbz.sufe.edu.cn"..uri)
        elseif string_contains(uri,"^/hqcy/") then
                if active_members("pool_hqcy_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                        pool("pool_hqcy_rs")  --pool_www2是节点池名称
                end               
        elseif string_contains(uri,"^/place/") then
        if active_members("pool_place_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                        pool("pool_place_rs")  --pool_www2是节点池名称
                end
        elseif         string_contains(uri,"^/saf/") then
        if         active_members("pool_security_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                    pool("pool_security_rs")
                end
        elseif         string_contains(uri,"^/zc/") then
        if         active_members("pool_gcms_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                    pool("pool_gcms_rs")
                end
        elseif         string_contains(uri,"^/health/") then
        if         active_members("pool_healthcare_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                    pool("pool_healthcare_rs")
                end        
        elseif         string_contains(uri,"^/mss/") then
        if         active_members("pool_mss_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                    pool("pool_mss_rs")
                end        
    else
            if         active_members("pool_newstu_rs") < 1 then
                    HTTP.respond(reply_page:value())
                    HTTP.close()
                else
                    pool("pool_newstu_rs")
                end
        end
}

打赏鼓励作者,期待更多好文!

打赏
1人已打赏

一个无趣的人 发表于 2023-9-15 16:15
  
楼主的文章图文并茂,清晰易懂,看完这波操作可以轻松上手了,如遇到问题再向楼主请教~
发表新帖
热门标签
全部标签>
设备维护
有一说一
新版本体验
山东区技术晨报
纪元平台
每日一问
功能体验
虚拟机
安装部署配置
解决方案
排障笔记本
测试报告
标准化排查
授权
技术盲盒
2024年技术争霸赛
问题分析处理
GIF动图学习
原创分享
资源访问
齐鲁TV
云化安全能力
日志审计
每日一记
sangfor周刊
地址转换
「智能机器人」
场景专题
2025年技术争霸赛
信服课堂视频
专家问答
技术圆桌
升级
玩转零信任
升级&主动服务
VMware替换
畅聊IT
上网策略
运维工具
用户认证
信服故事
平台使用
排障那些事
西北区每日一问
高手请过招
高频问题集锦
全能先锋系列
安全效果
产品连连看
安全攻防
华北区交付直播
每周精选
专家说
产品知识周周练
技术笔记
SDP百科
北京区每日一练
故障笔记
社区新周刊
行业实践
流量管理
产品动态
技术顾问
答题自测
在线直播
MVP
VPN 对接
项目案例
存储
产品预警公告
技术争霸赛
追光者计划
2023技术争霸赛专题
技术晨报
关键解决方案
声音值千金
网络基础知识
功能咨询
卧龙计划
华北区拉练
【 社区to talk】
工具体验官
终端接入
迁移
秒懂零信任
POC测试案例
专家分享
S豆商城资讯
天逸直播
SANGFOR资讯
以战代练
文档捉虫
产品解析
产品体验官
热门活动

本版达人

新手61940...

本周建议达人

zhao_HN

本周分享达人

ZSFKF

本周提问达人