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.arg[1]: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.arg[1] = ngx.arg[1]:gsub("</head>", script)

}

相关推荐
源远流长jerry8 小时前
从 Nginx 到 DPVS:高性能负载均衡之路
linux·网络·tcp/ip·nginx·负载均衡
guojb8249 小时前
告别部署踩坑:用 Docker Compose 优雅搞定多前端站点、HTTPS 与 SSE 推送
nginx·docker·https
NGINX开源社区10 小时前
F5 NGINX Gateway Fabric 2.4.0 新功能发布
nginx
**蓝桉**10 小时前
Nginx 负载均衡策略详解
运维·nginx·负载均衡
亚马逊云开发者10 小时前
证书 47 天就过期?我在 EC2 上用 Certbot 搞定了自动续期
nginx
夜影风10 小时前
Nginx部署Vue/React项目时无法直接访问页面其他路径的问题及解决方案
vue.js·nginx·react.js
小小的木头人10 小时前
Nginx 访问控制及安全配置文档
运维·nginx·安全
拾贰_C1 天前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
七七powerful1 天前
loki监控docker容器&系统&nginx日志的告警规则
nginx·docker·容器
dovens1 天前
httpslocalhostindex 配置的nginx,一刷新就报404了
运维·nginx