本文发布于Cylon的收藏册,转载请著名原文链接~

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
location = /reqq {
	default_type text/plain;
	content_by_lua_block {
		ngx.req.read_body()
		local data = ngx.req.get_body_data()
                local args, err = ngx.req.get_uri_args()
		if not args then
			ngx.say('post fail')
			return
		end
		
        for key,v in pairs(args) do
			ngx.say(key,"::",v,"--")
		end
		ngx.say(data)
	}
}

ngx.exec 内部重定向

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
location = /bb {
    default_type text/plain;
    content_by_lua_block{
        ngx.exec('/reqq?m=DaoShengPay3&c=Pay&orderNo=PH201910111')
    }
}

location = /reqq {
    default_type text/plain;
    content_by_lua_block {
       ngx.req.read_body()
       local data = ngx.req.get_body_data()
       local args, err = ngx.req.get_uri_args()
       if not args then
               ngx.say('post fail')
               return
       end
       for key,v in pairs(args) do
               ngx.say(key,"::",v,"--")
       end
       ngx.say(data)
    }
}

1570889980396

ngx.log

1
2
3
4
5
6
7
location = /testlog {
    default_type text/plain;
    content_by_lua_block{
        ngx.say('hello lua log')
        ngx.log(ngx.ERR, 'print hello lua log')
    }
}
1
2019/10/12 22:25:31 [error] 468#0: *248 [lua] content_by_lua(nginx.conf:44):3: print hello lua log, client: 203.90.247.72, server: test111.hou2008.com, request: "GET /testlog HTTP/1.1", host: "test111.hou2008.com:8181", referrer: "http://test111.hou2008.com/testlog"

Nginx API for Lua

https://github.com/openresty/lua-nginx-module

https://www.zifangsky.cn/1024.html

本文发布于Cylon的收藏册,转载请著名原文链接~

链接:https://www.oomkill.com/2019/10/lua-nginx-api/

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」 许可协议进行许可。