需求:
需要一个GET接口,进行数据查询测试
准备:
1000万条数据文件:
Linux服务器安装openresty与安装 sockproc与安装lua-resty-shell模块:
Nginx调用Shell脚本全环境配置_承缘丶的博客-CSDN博客
配置Nginx服务:
首先可以通过whereis nginx 查看nginx安装的位置,默认在/usr/local/openresty/nginx/sbin/nginx目录下,所以也可以通过nginx reload命令单独reload nginx。
location /test {
lua_need_request_body on;
default_type application/json;
content_by_lua_file /lyg/tools/test.lua;
}
lua文件如下:
local head = ngx.var.arg_head
local tail = ngx.var.arg_tail
-- local httpUri = ngx.unescape_uri(ngx.var.request_uri)
local shell = require "resty.shell"
local args = {
socket = "unix:/var/run/shell.sock",
}
local cmd = "cat -n /lyg/ceshi_copy1.txt | head -n " .. head .." | tail -n " .. tail
local status, out, err = shell.execute(cmd, args)
ngx.header.content_type = "text/plain"
ngx.say("Result:\n" .. out )