Skip to content

Instantly share code, notes, and snippets.

@ducmeit1
Created August 21, 2019 05:21
Show Gist options
  • Save ducmeit1/5afdc97ca6ffefd2fbe5ec07a4a2577c to your computer and use it in GitHub Desktop.
Save ducmeit1/5afdc97ca6ffefd2fbe5ec07a4a2577c to your computer and use it in GitHub Desktop.
upstream backend {
192.168.0.1:8000; #server 1
192.168.0.2:8001; #server 2
balancer_by_lua_block {
//write your round robin code here
local host, port = picked_server()
if not host and not port then
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("no live upstream")
ngx.exit(ngx.HTTP_OK)
return
end
local ok, err = balancer.set_current_peer(host, port)
if not ok then
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("failed to set current peer")
ngx.exit(ngx.HTTP_OK)
return
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment