nginx-lua get post请求小例子
来源:互联网 发布:腋下汗毛怎么去掉知乎 编辑:程序博客网 时间:2024/06/05 21:57
nginx 启动,停止,重启命令(电脑为ubuntu环境),参考:http://wenku.baidu.com/link?url=B7X7OUwxb9Gp29kUfPO3EHDt9rksUQ_ltNTB95Yq9NZSTlLl-dEZjMe3ZdtC0FTVK7H_NGe1vGkOxSMdm2je4O8G3VqXiW7TATriKVkQB6S
sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/conf/nginx.conf 修改配置文件, 加上自己的url
这里采用了include 方法,其实就是写在/usr/local/nginx/conf/nginx.conf文件中
Nginx安装及配置文件: http://www.cszhi.com/20120513/nginx_nginx-conf.html
安装Nginx+Lua+OpenResty开发环境配置全过程实例
http://www.cnblogs.com/zdz8207/p/Nginx-Lua-OpenResty.html
http { include mime.types; default_type application/octet-stream; #lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找 #lua_package_path "/usr/servers/lualib/?.lua;;"; #lua 模块 #lua_package_cpath "/usr/servers/lualib/?.so;;"; #c模块
nginx_test.conf(nginx_test.conf 把location定义好)
如下的location /test/post_2 即使一个指定路径 , 并且指定了处理请求的文件是 hello_http.lua
location /test/post_1{content_by_lua 'ngx.req.read_body()local args = ngx.req.get_post_args()for key, val in pairs(args) doif type(val) == "table" thenngx.say(key, ": ", table.concat(val, ", "))elsengx.say(key, ": ", val)endend';}location /test/post_2{ lua_need_request_body on ; default_type 'text/plain' ; content_by_lua_file /home/ding/data/luafile/hello_http.lua ;}
hello.http.lua 文件内容如下,主要是接收到post请求的body后,对post参数进行遍历输出
local request_method = ngx.var.request_methodlocal args = nilngx.say('处理htpp请求,get或post请求的参数如下')if "GET" == request_method then ngx.say("get请求") args = ngx.req.get_uri_args()elseif "POST" == request_method then ngx.say("post请求") ngx.req.read_body() args = ngx.req.get_post_args()endfor key, val in pairs(args) doif type(val) == "table" thenngx.say(key, ": ", table.concat(val, ", "))elsengx.say(key, ": ", val)endendngx.say('get or post request over')
测试结果
参考学习
nginx-lua : http://outofmemory.cn/code-snippet/14396/nginx-and-lua
curl请求:http://blog.sina.com.cn/s/blog_6e2d53050101k230.html
0 0
- nginx-lua get post请求小例子
- $.get()/$.post()/$ajax() 异步请求的例子
- golang带cookie post get请求 例子
- Node.js GET/POST请求简单例子
- nginx只允许get/post请求
- lua获取请求的请求方法(get,post)
- Nginx服务器中使用lua获取get或post参数
- HttpURLConnection的GET请求POST请求小总结
- GET请求 Post请求
- get请求 post请求
- Get请求 Post请求
- 异步的HTTP POST与GET请求例子
- 异步的HTTP POST与GET请求例子
- Android例子—HttpURLConnection发送POST、GET请求代码示例
- lua 发送post请求
- 16.POST、GET请求
- iOS get post请求
- http post get 请求
- 一段很巧妙的直方图统计算法代码
- java 题目笔记
- CSS控制图片和文字在同一行显示且对齐的3种方法
- 微信扫码支付Demo(java)
- 破坏网络可信身份认证,黑灰产业链正在兴起
- nginx-lua get post请求小例子
- iOS 中使用token机制来验证用户的安全性
- 统计学习笔记(1) 监督学习概论(1)
- android ViewPager适配器
- 采用dlopen、dlsym、dlclose加载动态链接库【总结】
- js更改来源页面所搜内容,js referrer
- PHP socket实现和Java端readFully对接
- CUDA范例精解通用GPU架构-(1)Tesla服务器Kepler架构和万年的HelloWorld
- 最新的京东省市区数据xml