access_by_lua_block {
if "GET" == ngx.var.request_method then
args,err = ngx.req.get_uri_args()
if err or not args['appKey'] or not args['appSecret'] then
ngx.var.access = 0
return
end
-- 如果args增加local变为本地变量,这里调用args会为nil。
elseif "POST" == ngx.var.request_method then
ngx.req.read_body()
-- args = ngx.req.get_post_args()
args = ngx.req.get_body_data()
if not args['appKey'] or not args['appSecret'] then
ngx.var.access = 0
return
end
end
}
这是配置文件,想要完成判断请求并获取请求体中的内容,在使用GET请求时,曾经在变量args前增加local,然后发现args只能在if中调用才有数据。在使用POST时,在日志文件中发现了图中错误,不知道是由于什么问题产生的,谢谢您的帮助。2019/07/26 17:41:39 [error] 6361#6361: *59 "/home/xxx/work/html/index.html" is forbidden (13: Permission denied), client: 172.16.1.59, server: , request: "POST / HTTP/1.1", host: "172.16.0.38:7088"2019/07/26 17:41:39 [error] 6361#6361: *59 "/home/xxx/work/html/index.html" is forbidden (13: Permission denied), client: 172.16.1.59, server: , request: "POST / HTTP/1.1", host: "172.16.0.38:7088"