2 lua
来源:互联网 发布:硬件检测软件大全 编辑:程序博客网 时间:2024/05/22 13:21
nginx.conf
#user nobody;worker_processes 2;events { worker_connections 1024;}http { include mime.types; default_type text/html; lua_package_path "/usr/servers/lualib/?.lua;;"; lua_package_cpath "/usr/servers/lualib/?.so;;"; #include lua.conf; include /usr/example/example.conf;}
example.conf
server { listen 8080; server_name _; location /lua { default_type 'text/html'; lua_code_cache off; # content_by_lua 'ngx.say("hello world")'; content_by_lua_file /usr/example/lua/test.lua; } location ~ /lua_request/(\d+)/(\d+) { lua_code_cache off; #设置nginx变量 set $a $1; set $b $host; default_type "text/html"; #nginx内容处理 content_by_lua_file /usr/example/lua/test.lua; # content_by_lua_file /usr/example/lua/test_request.lua; #内容体处理完成后调用 echo_after_body "ngx.var.b $b"; } }
test.lua
--nginx变量 ngx.say("hello word")local var = ngx.var ngx.say("ngx.var.a : ", var.a, "<br/>") ngx.say("ngx.var.b : ", var.b, "<br/>") ngx.say("ngx.var[2] : ", var[2], "<br/>") ngx.var.b = 2; ngx.say("<br/>") ngx.say("-------------------------------------")--请求头 local headers = ngx.req.get_headers() ngx.say("headers begin", "<br/>") ngx.say("Host : ", headers["Host"], "<br/>") ngx.say("user-agent : ", headers["user-agent"], "<br/>") ngx.say("user-agent : ", headers.user_agent, "<br/>") for k,v in pairs(headers) do if type(v) == "table" then ngx.say(k, " : ", table.concat(v, ","), "<br/>") else ngx.say(k, " : ", v, "<br/>") end end ngx.say("headers end", "<br/>") ngx.say("<br/>") ngx.say("-------------------------------------")--post请求参数 ngx.req.read_body() ngx.say("post args begin", "<br/>") local post_args = ngx.req.get_post_args() for k, v in pairs(post_args) do if type(v) == "table" then ngx.say(k, " : ", table.concat(v, ", "), "<br/>") else ngx.say(k, ": ", v, "<br/>") end end ngx.say("post args end", "<br/>") ngx.say("<br/>") ngx.say("-------------------------------------")--未经解码的请求uri local request_uri = ngx.var.request_uri; ngx.say("request_uri : ", request_uri, "<br/>"); --解码 ngx.say("decode request_uri : ", ngx.unescape_uri(request_uri), "<br/>"); --MD5 ngx.say("ngx.md5 : ", ngx.md5("123"), "<br/>") --http time ngx.say("ngx.http_time : ", ngx.http_time(ngx.time()), "<br/>") ngx.say("-------------------------------------")--请求的http协议版本 ngx.say("ngx.req.http_version : ", ngx.req.http_version(), "<br/>") --请求方法 ngx.say("ngx.req.get_method : ", ngx.req.get_method(), "<br/>") --原始的请求头内容 ngx.say("ngx.req.raw_header : ", ngx.req.raw_header(), "<br/>") --请求的body内容体 ngx.say("ngx.req.get_body_data() : ", ngx.req.get_body_data(), "<br/>") ngx.say("<br/>")
阅读全文
0 0
- Lua - 2
- Lua(2)
- 2 lua
- Lua.2 lua的表达式
- 学习Lua(2) -- Lua 简单示例
- 自学Lua(2)--Lua表达式
- 我是Lua初学者【2】
- Lua使用心得(2)
- lua学习笔记(2)
- Lua语言教程2
- lua 基础2
- lua进阶2
- lua(2) table排序
- lua学习笔记2
- lua 全局变量 2
- Lua chapter 2
- Lua基础(2)
- lua学习2
- 数据可视化之美
- C++11新特性之八——函数对象function
- MySQL大数据量分页性能优化
- JAVA课程作业2-生成数独问题
- 4·RHCSA用户账户操作
- 2 lua
- supervisor管理进程停止异常问题记录
- vuejs(3)
- 注释最全的Android购物车简单实现,复制可用,阅读可懂
- 实验4:栈和队列的基本操作实现及其应用之《链队列》
- 用pyinstaller将python程序转化为exe格式。
- iOS 使用plist和归档存储数据
- Windows下flask环境的搭建
- python圣斗士修炼(七)