upstream weblist {
server 192.168.1.2:80 weight=1;
server 192.168.1.3:80 weight=1;
}
server {
listen 8080
default_server;
server_name _;
location /cache {
default_type text/html;
content_by_lua_block {
local http = require "resty.http"
local httpc = http.new()
local upstream = require "ngx.upstream"
local get_servers = upstream.get_servers
local srvs, err = get_servers("nlp")
if not srvs then
ngx.say("failed to get servers in upstream ", u)
else
for _, srv in ipairs(srvs) do
for k, v in pairs(srv) do
if k== "addr" then
ngx.req.read_body()
local res,err res, err = httpc:request_uri("http://"..v.."/cache" , {
method = ngx.var.request_method,
body = ngx.var.request_body
})
if res.status == ngx.HTTP_OK then
ngx.say(res.bdoy)
end
end
end
end
end
}
}
location / {
proxy_pass http://nlp;
proxy_redirect off;
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_ignore_client_abort on;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream http_500 http_502 http_503 http_504;
}
}