Nginx lua 接收 GET/POST 请求

有时候写一些简单的api 接口如果不想再起个php-fpm ,完全可以通过nginx加lua在nginx 直接实现。

当然前提是你必须给nginx安装 lua-nginx-module 模块。

下面是nginx 的配置及lua 代码:

lua_need_request_body on;  location = /api {      default_type text/plain;      content_by_lua_block {          ngx.req.read_body()          // 获取Post 数据          local post = ngx.req.get_post_args()          // 获取Querystring 数据          local get = ngx.req.get_uri_args()          ngx.say(post.name)          ngx.say(post.gender)          ngx.say(get.type)      }    }  

content_by_lua_block 中放lua 代码

打开命令行模拟请求测试一下

curl  -XPOST 'http://test-lua.loc/mm?type=good' -d "name=shanhuhai" -d "gender=1"  

原文出处:dahouduan -> http://www.dahouduan.com/2017/09/22/nginx-lua-receive-get-post/

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。