From 5191044d8a2e1c57ef1198e47a7ac7e113a593e3 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qqcom> Date: Fri, 17 Oct 2025 10:16:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95cjson?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=92=8C=E8=AF=B7=E6=B1=82=E4=BD=93=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E7=9A=84=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/nginx.conf | 5 ++++- conf/system/test.conf | 4 ++++ src/test/test.lua | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 53f3559..9af0994 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,4 @@ -worker_processes 1; #nginx worker 数量 +worker_processes auto; #nginx worker 数量 error_log logs/error.log; #指定错误日志文件路径 #worker_rlimit_nofile 65535; @@ -8,6 +8,9 @@ events { } http { + client_max_body_size 10k; #允许最大100k的请求体 + client_body_buffer_size 4k; #设置缓冲区大小 + lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;;'; lua_package_cpath '$prefix/src/share/lib/?.so;;'; diff --git a/conf/system/test.conf b/conf/system/test.conf index ac50dd7..70ba431 100644 --- a/conf/system/test.conf +++ b/conf/system/test.conf @@ -1,4 +1,8 @@ #测试接口文件 location /testSQL { content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua'; +} + +location /cjson { + content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua'; } \ No newline at end of file diff --git a/src/test/test.lua b/src/test/test.lua index 79aa0ba..d71db47 100644 --- a/src/test/test.lua +++ b/src/test/test.lua @@ -2,4 +2,36 @@ --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by admin. --- DateTime: 2025/10/15 09:12 ---- \ No newline at end of file +--- + +--读取请求体的数据 +ngx.req.read_body() + +--获取请求数据 +local body_data = ngx.req.get_body_data() + +if not body_data then + ngx.say("read file error:"..err) + return ngx.exit(400) +end + +ngx.say(body_data) + + +--local cjson = require("cjson") +--local file_path = "/home/frankly/work/test.dat" +--local file_length = 1024 * 1024 * 380 +--local f, err = io.input(file_path, "r") +--if not f then +-- ngx.say("read file error:"..err) +-- return +--end +--local content = f:read(file_length) --读取文件内容 +--f:close() --关闭文件 +----ngx.say(content) +--local res = { +-- key = "data", +-- value = content +--} +--ngx.header["Content-Type"] = 'application/json; charset=UTF-8' +--ngx.say(cjson.encode(res)) \ No newline at end of file