openresty中capture_multi如何与upstream结合使用?,
openresty中capture_multi如何与upstream结合使用?,
把前端的请求经由nginx多路转发给后台的apache以及tomcat服务器,然后对后台服务器返回的数据做一些归并和排序处理。下面是nginx.conf配置。
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 51200;
}
http {
upstream cluster_1 { //apache servers
server localhost:10001;
}
upstream cluster_2 { //tomcat servers
server localhost:10002;
}
server {
listen 10000;
server_name localhost;
location /multi {
proxy_pass_request_headers off;
content_by_lua '
local res1, res2 = ngx.location.capture_multi{
{ "/s1" },
{ "/s2" },
}
ngx.say(res1.status);
if res1.status == ngx.HTTP_OK then
ngx.print(res1.body);
end
';
}
location /s2 {
proxy_pass http://cluster_2;
}
}
}
评论暂时关闭