location /sgz {
content_by_lua_block {
-- 引入的模块
local cjson = require "cjson"
local file = io.open("/www/sites/********/index/sgz.json", "r")
if not file then
ngx.say("Failed to read sgz.json")
return
end
local content = file:read("*a") -- 读取文件内容
file:close()
local data = cjson.decode(content) -- 解析json数据
-- 获取请求参数
local args = ngx.req.get_uri_args()
local question = args["question"]
if not question then
ngx.say("没有参数")
return
end
-- 遍历json数据,查找匹配的问题
for _, item in ipairs(data) do
if item["question_name"] == question then
ngx.say(item["right_name"]) -- 返回匹配的答案
return
end
end
-- 如果没有找到匹配的问题,返回错误信息
ngx.say("没有找到该题目")
}
}
当我添加了以上内容至配置文件后,无法进行修改和查看该域名下的日志、安全等