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

俞健 42371人觉得有帮助

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

本版达人

新手61940...

本周建议达人

zhao_HN

本周分享达人

ZSFKF

本周提问达人