local method = ngx.var.request_method;
local headers = ngx.req.get_headers();
local uri_args = ngx.req.get_uri_args();
-- 逆序排列函数
function reverseTable(tab)
local tmp = {}
for i = 1, #tab do
local key = #tab
tmp[i] = table.remove(tab)
end
return tmp
end
if method == "GET" then
ngx.say("version2.0");
local opt = uri_args["opt"];
if("r" == opt) then
file = io.open("/logs/httppost.log", "r");
file:seek("end", -8000);
local content = file:read("*l");
local count = 1;
array = {};
while(nil ~= content) do
--ngx.say(content);
array[count]=content;
count = count+1;
content = file:read();
end
file:close();
newArray=reverseTable(array);
for i=1,#newArray do
ngx.say(newArray[i]);
end
else
ngx.say("操作不是读文件");
end
end
注:Linux默认文件是没有写权限的,如果写文件的话注意给文件开启写权限