lua-resty-core
lua-resty-core copied to clipboard
Can i use content_by_lua_file when using ngx.balancer
stream {
upstream backend {
server 0.0.0.1:1234; # just an invalid address as a place holder
balancer_by_lua_block {
local balancer = require "ngx.balancer"
local host = "127.0.0.2"
local port = 8080
local ok, err = balancer.set_current_peer(host, port)
if not ok then
ngx.log(ngx.ERR, "failed to set the current peer: ", err)
return ngx.exit(ngx.ERR)
end
}
}
server {
# this is the real entry point
listen 10000;
location / {
content_by_lua_file xxxx;
proxy_pass backend;
}
}
}
God Zhang, if i want to do some process on the url request in the content, however, i found this didn't work here when i put content_by_lua_file before proxy_pass.
So, how can i deal with the request before the balancer?
Thx
@vtroop
There could be only one handler in Nginx's "content phase", either content_by_lua_file or proxy_pass.
Instead you could put some of your business logic in rewrite_by_lua_file or access_by_lua_file, which are in front of the "content phase".
@spacewander Thx, the access can statisfy my nedd. i will close the issue