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)

}

相关推荐
名字还没想好☜11 小时前
Nginx 反向代理与负载均衡配置实战
运维·nginx·负载均衡
砍材农夫14 小时前
运维|devops|nginx|基本配置拆解
运维·nginx·devops
三84414 小时前
笔记:在同一个物理服务器上通过nginx的虚拟主机生成多个不同的web站点
java·前端·nginx
lastHertz1 天前
Nginx安装部署
运维·nginx
开发小程序的之朴2 天前
安企CMS的安装-PHPStudy(小皮面板)部署
windows·mysql·nginx
MMendex2 天前
Nginx_day4——uWSGI,灰度发布,网站限流限速,Nginx跨域
运维·nginx
明月心9522 天前
https配置
nginx·https配置
Ai拆代码的曹操2 天前
TCP RST 包全链路定位:从 Connection Reset 错误到 Nginx keepalive_timeout 不匹配
网络协议·tcp/ip·nginx
她叫我大水龙2 天前
nginx 编译指南:静态编译 + 动态编译
运维·nginx
Icoolkj3 天前
ICOOLKJ 前后端分离项目完整部署文档(MySQL8.4+Redis+JDK21+Nginx+HTTPS+自动同步演示库)
redis·nginx·https