lua脚本动态插入script标签 在nginx层面

body_filter_by_lua_block{

local pin = ngx.var.cookie_jrapp_jsfGateway_testPin

local domain = ngx.var.host

local scheme = ngx.var.scheme

local title = "白条"

local match = ngx.arg1:match("<title>(\^\<+)</title>")

if match then

title = match

end

if not pin then

pin = "未知pin"

end

local script = string.format('<script crossorigin=\"anonymous\" src=\"%s://%s/page-spy/index.min.js\"></script><script>window.$pageSpy=new PageSpy({ project: \"%s\", title: \"%s\" })</script></head>', scheme,domain,title, pin)

ngx.arg1 = ngx.arg1:gsub("</head>", script)

}

相关推荐
白驹过隙不负青春10 小时前
OpenResty 1.29.2.5 部署 + Nginx平滑升级运维文档
nginx·openresty
大黄说说10 小时前
Hyperf 协程 PHP 实战:高并发秒杀接口从 0 到 1 落地
junit
Cry丶12 小时前
一次 FTP 上传引发 504 Gateway Timeout 的排查复盘
java·nginx·ftp·openresty·被动模式·504 gateway·生产问题排查
一勺菠萝丶1 天前
生产环境平滑升级实战-Nginx维护页数据库迁移与安全回滚
数据库·nginx·安全
吴声子夜歌1 天前
Redis 3.x——事务与Lua
redis·lua
Helen_cai1 天前
OpenHarmony 路由封装 RouterUtil 页面跳转统一管理(API Version23+)
运维·服务器·nginx·华为·harmonyos
云计算磊哥@1 天前
运维开发宝典055-大型网站nginx服务器管理全集1
服务器·nginx·运维开发
碎碎念_4922 天前
前后端分离项目开发规范
nginx·vue·springboot·restful
刘某的Cloud2 天前
手工配置nginx的systemd服务
linux·运维·网络·nginx·systemd
刘某的Cloud2 天前
Nginx 最小安全配置模板
linux·运维·nginx·安全·系统