apache_conf openresty负载均衡下的特殊应用 - 特定请求转发所有后端主机

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf openresty负载均衡下的特殊应用 - 特定请求转发所有后端主机相关的知识,希望对你有一定的参考价值。

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; 
    } 
}

以上是关于apache_conf openresty负载均衡下的特殊应用 - 特定请求转发所有后端主机的主要内容,如果未能解决你的问题,请参考以下文章

openresty用haproxy2.0实现负载均衡

网关开发5.Openresty 自定义负载均衡与流量转发

负载均衡基于Cookie OpenRest+tomcat+php+memcache+Jsp

NGINX 负载均衡策略之「快者优先」的 Lua 实现

9.Kong入门与实战 基于Nginx和OpenResty的云原生微服务网关 --- 高级进阶

云负载均衡与WAF人才在那里?