测试环境中需要一些数据,可以自己仿造数据,不过最方便的方法是:将来自正式环境的用户请求copy一份到测试环境。 使用模块需要重新编译
复制代码代码示例:
nginx, –add-module=/path/to/your/module
nginx配置:
复制代码代码示例:
>>cat copy_req.lua
local res1, res2, action action = ngx.var.request_method if action == “POST” then arry = {method = ngx.HTTP_POST, body = request_body} else arry = {method = ngx.HTTP_GET} end if ngx.var.svr == “on” then res1, res2 = ngx.location.capture_multi { { “/s1″ .. ngx.var.request_uri , arry}, { “/test” .. ngx.var.request_uri , arry}, } else res1, res2 = ngx.location.capture_multi { { “/s1″ .. ngx.var.request_uri , arry}, } end if res1.status == ngx.HTTP_OK then local header_list = {“Content-Length”, “Content-Type”, “Content-Encoding”, “Accept-Ranges”} for _, i in ipairs(header_list) do if res1.header[i] then ngx.header[i] = res1.header[i] end end ngx.say(res1.body) else ngx.status = ngx.HTTP_NOT_FOUND end >>cat nginx.conf …….. location ~* ^/s1 { log_subrequest on; rewrite ^/s1(.*)$ $1 break; proxy_pass http://s1; access_log /opt/logs/nginx/youni/upstream.log; } location ~* ^/test { log_subrequest on; rewrite ^/test(.*)$ $1 break; proxy_pass http://test; access_log /opt/logs/nginx/youni/upstream.log; } location ~* ^/(.*)$ { client_body_buffer_size 2m; set $svr “on”; #开启或关闭copy功能 content_by_lua_file req_fenliu.lua; } upstream s1 { server x.x.x.x; } upstream test { server xx.xx.xx.xx; } …… 其中的nginx.conf内的http,server域没有放上来,大家根据自己的实际情况配置即可。 (责任编辑:IT) |