Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- default.conf
- location /proxy {
- proxy_pass http://127.0.0.1:8001/;
- rewrite_by_lua_file ./lua/set_by_file.lua;
- }
- ######### lua/set_by_file.lua
- local pretty = require "resty.prettycjson"
- function getval(v, def)
- if v == nil then
- return def
- end
- return v
- end
- local data = {request={}, response={}}
- local req = data["request"]
- local resp = data["response"]
- req["host"] = ngx.var.host
- req["uri"] = ngx.var.uri
- req["headers"] = ngx.req.get_headers()
- req["time"] = ngx.req.start_time()
- req["method"] = ngx.req.get_method()
- req["get_args"] = ngx.req.get_uri_args()
- req["body"] = ngx.var.request_body
- content_type = getval(ngx.var.CONTENT_TYPE, "")
- resp["headers"] = ngx.resp.get_headers()
- resp["status"] = ngx.status
- resp["duration"] = ngx.var.upstream_response_time
- resp["time"] = ngx.now()
- resp["body"] = ngx.var.response_body
- local hasilnya = pretty({data})
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1 sec
- -- or connect to a unix domain socket file listened
- -- by a redis server:
- -- local ok, err = red:connect("unix:/path/to/redis.sock")
- local ok, err = red:connect("127.0.0.1", 6379)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ok, err = red:set("dog", pretty({data}))
- if not ok then
- ngx.say("failed to set dog: ", err)
- return
- end
- ngx.say("set result: ", ok)
Advertisement
Add Comment
Please, Sign In to add comment