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)

}

相关推荐
测试界清流10 小时前
Postman接口测试入门
开发语言·lua
源猿人10 小时前
nginx代理如何配置和如何踩到坑篇
前端·nginx
Volunteer Technology13 小时前
Lua基础+Lua数据类型
开发语言·junit·lua
苹果醋315 小时前
从零搭建React框架--第一章:create-react-app、antd、less
运维·vue.js·spring boot·nginx·课程设计
子洋19 小时前
Ubuntu 安装 Nginx
前端·后端·nginx
Volunteer Technology20 小时前
openresty-lua-redis案例
redis·lua·openresty
苹果醋31 天前
React Native jpush-react-native极光推送 iOS生产环境接收不到推送
java·运维·spring boot·mysql·nginx
竹竿袅袅2 天前
Nginx 反向代理与负载均衡架构
nginx·架构·负载均衡
Clownseven2 天前
Nginx反向代理教程:配置多个网站并一键开启HTTPS (Certbot)
运维·nginx·https
苹果醋33 天前
Deep Dive React 4 How does React State actually work
java·运维·spring boot·mysql·nginx