Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy_next_upstream配置对使用balancer_by_lua_block后的集群无效 #51

Closed
onlonely opened this issue Jul 18, 2016 · 1 comment
Closed

Comments

@onlonely
Copy link

如下配置,当访问http://127.0.0.1:8800/test2时出现404
`
proxy_next_upstream error timeout invalid_header http_504 http_404;#什么样的错误分发自动重试
proxy_http_version 1.1;
proxy_set_header Connection "";

server {access_log logs/access.log;server_name up_1;listen 8801;
location /test1 {content_by_lua 'ngx.say(ngx.var.server_port,":",ngx.var.uri)';}
}
server {access_log logs/access.log;server_name up_2;listen 8802;
location /test2 {content_by_lua 'ngx.say(ngx.var.server_port,":",ngx.var.uri)';}
}
server {server_name up_0;listen 8800;
location =/favicon.ico { return 200;}
location / {
proxy_pass http://up_test;
log_by_lua '
ngx.log(ngx.ERR,"\nuri=",ngx.var.uri,"upstream_addr:",ngx.var.upstream_addr,"upstream_status:",ngx.var.upstream_status)
';
}
}
upstream up_test {
server 0.0.0.1; # just an invalid address as a place holder
balancer_by_lua_block {
local balancer = require "ngx.balancer"
local upservers={3,
{"127.0.0.1",8801},
{"127.0.0.1",8802},
{"127.0.0.1",8803}
}
local state_name, status_code = balancer.get_last_failure()
ngx.log(ngx.ERR,"\nstate_name:",state_name, "status_code:",status_code)

local ibf=require "randombuff"
local index=ibf.index()--每次递增+1,模拟轮询负载均衡策略
index=math.mod(index,upservers[1])+2
local ok, err = balancer.set_current_peer(upservers[index][1], upservers[index][2])
ngx.log(ngx.ERR,"n\uri:",ngx.var.uri,"index;",index,"ok:",ok, err)
if not ok then
    ngx.log(ngx.ERR, "failed to set the current peer: ", err)
    return ngx.exit(500)
end          
}
keepalive 10;  # connection pool

}`
如果是如下集群配置则不会404
upstream up_test2 {
server 127.0.0.1:8801;
server 127.0.0.1:8802;
server 127.0.0.1:8803;
keepalive 10;
}
请问是BUG还是我写法不对呢

@agentzh
Copy link
Member

agentzh commented Jul 18, 2016

@onlonely First of all, please do not use Chinese here. This place is considered English ONLY.

Regarding your problem, you should call the set_more_tries lua method explicitly:

https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md#set_more_tries

zhuizhuhaomeng added a commit that referenced this issue Jun 1, 2022
test 1/2: upstream send extra data.
test 3: upstream close the connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants