#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 = {m Ethod = 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--[[using Master's response header--]] for k,v in pairs (master_resp.header) do Ngx.header[k] = V end Ngx.say (master_resp.body)}} Locati On ~* ^/master {internal; Rewrite ^/master (. *) $ $ break; Proxy_pass Http://master; } location ~* ^/slave {internal; Log_subrequest on; Rewrite ^/slave (. *) $ $ break; Proxy_pass Http://slave; Access_log Logs/upstream.log; } }}
Openrsty (nginx_lua_module) do es Proxy and back up ES data