首页 > 代码库 > openrsty(nginx_lua_module)做ES代理以及备份ES数据
openrsty(nginx_lua_module)做ES代理以及备份ES数据
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { upstream master { server 10.1.1.100:9200; server 10.1.1.100:9200 backup;#备份库 keepalive 15; } upstream slave {#备份库 server 10.1.1.100:9200; keepalive 15; } server { server_name localhost 127.0.0.1 10.1.1.225; listen 8888; location / { content_by_lua_block { local function getFile(file_name) local f = assert(io.open(file_name, ‘r‘)) local string = f:read("*all") f:close() return string end ngx.req.read_body() ngx.log(ngx.ERR, ‘$$$‘ ..ngx.var.request_uri .. ‘$$$‘) local request_body = ngx.req.get_body_data() if nil == request_body then local file_name = ngx.req.get_body_file() if file_name then request_body = getFile(file_name) end end local master_resp, slave_resp local req_method_constant = ngx[‘HTTP_‘ .. ngx.req.get_method()] local arry = {method = req_method_constant, body = request_body} if req_method_constant == ngx.HTTP_POST or req_method_constant == ngx.HTTP_PUT or req_method_constant == ngx.HTTP_DELETE then master_resp, slave_resp = ngx.location.capture_multi{ {‘/slave‘ .. ngx.var.request_uri, arry}, {‘/master‘ .. ngx.var.request_uri, arry} } else master_resp = ngx.location.capture_multi{ {‘/master‘ .. ngx.var.request_uri, arry} } end --[[ 使用master的响应头 --]] for k,v in pairs(master_resp.header) do ngx.header[k] = v end ngx.say(master_resp.body) } } location ~* ^/master { internal; rewrite ^/master(.*)$ $1 break; proxy_pass http://master; } location ~* ^/slave { internal; log_subrequest on; rewrite ^/slave(.*)$ $1 break; proxy_pass http://slave; access_log logs/upstream.log; } } }
openrsty(nginx_lua_module)做ES代理以及备份ES数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。