freshUser想使用openresty实现根据POST请求的body进行转发。如请求体中包含abc。 则转发到www.example1.com;包含efg时,转发到www.test.com。 一步步学习成本太高,有人能提供一个可使用的nginx.conf文件模板吗?
location / {
set $proxy "";
rewrite_by_lua '
ngx.req.read_body()
local body = ngx.var.request_body
if (body) then
local match = ngx.re.match(body, "STRING TO FIND")
if match then
ngx.var.proxy = "www.ServerA.com"
else
ngx.var.proxy = "www.ServerB.com"
end
else
ngx.status = ngx.HTTP_NOT_FOUND
ngx.exit(ngx.status)
end
';
proxy_pass http://$proxy$uri;
}
这种自己不写出来,后面也会遇到一堆的问题