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)

}

相关推荐
摘星编程9 小时前
Nginx 502 Bad Gateway:从 upstream 日志到 FastCGI 超时复盘
网络·nginx·gateway·php-fpm·fastcgi
通明湖18 小时前
NJet深层清理Lua代码
nginx·lua
子兮曰19 小时前
🔥这个Nginx泛域名配置,让90%的开发者直呼"原来还能这样玩!
运维·前端·nginx
曾经的三心草21 小时前
微服务的编程测评系统20-虚拟机-nginx-部署
数据库·nginx·微服务
大飞pkz1 天前
【Lua】题目小练14
开发语言·lua·练习·题目·题目小练
海洋猿1 天前
nginx配置端口转发(docker-compose方式、包括TCP转发和http转发)
运维·nginx·docker·端口转发
cxyll12341 天前
postman 用于接口测试,举例
开发语言·lua·接口测试·postman
鱼鱼说测试2 天前
postman带Token测试接口
开发语言·lua
一行•坚书2 天前
怎么用redis lua脚本实现各分布式锁?Redisson各分布式锁怎么实现的?
redis·分布式·lua
你我约定有三2 天前
Redis--Lua脚本以及在SpringBoot中的使用
spring boot·redis·lua