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)

}

相关推荐
難釋懷30 分钟前
Nginx-Https证书配置
运维·nginx·https
风向决定发型丶1 小时前
Logrotate配置nginx日志切割
运维·nginx
難釋懷1 小时前
Nginx自签名-OpenSSL
运维·chrome·nginx
五阿哥永琪17 小时前
Nginx入门教学+实战
运维·nginx
热爱Liunx的丘丘人1 天前
Docker Compose 实现 Nginx 与 MySQL 多容器服务编排
mysql·nginx·docker
tang7451639621 天前
Ubuntu 24.04 安装 Nginx 1.29.6 完整版教程20260320
linux·nginx·ubuntu
小糖学代码1 天前
LLM系列:环境搭建:4.Nginx使用教程
运维·python·神经网络·nginx
sg_knight1 天前
负载均衡配置:使用 Nginx 反向代理 MinIO 集群的实战教程
运维·nginx·负载均衡·文件管理·minio·cos·oss
ruanyongjing1 天前
元数据驱动开发 - 面向对象编程思想的补充 (十二)
nginx·macos·docker
wh_xia_jun1 天前
Apifox 测试项目实操1
开发语言·lua