我正在尝试配置 NGINX/OpenResty 以根据 SOAP 请求上存在的字符串将 SOAP 调用代理到 2 个不同的服务器。
我能做什么:我能够根据 SOAP 客户端调用的路径将请求代理到 2 个不同的服务器:
location /pathA {
proxy_pass http://www.ServerA.com/PathA/;
}
location /pathB {
proxy_pass http://www.ServerB.com/PathB/;
}
Run Code Online (Sandbox Code Playgroud)
我不能做什么:
我无法根据请求的内容分离流量。我认为主要原因是我无法正确组装LUA脚本来提取信息并随后使用它来代理请求。
location / {
conten_by_lua '
ngx.req.read_body()
local match = ngx.re.match(ngx.var.request_body,"STRING TO FIND")
if match then
proxy_pass http://www.ServerA.com/PathA/;
else
proxy_pass http://www.ServerB.com/PathB/;
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我安装了 OpenResty 并且 LUA 工作正常。
我想我在某处读到如果请求不是 HTTP POSTngx.req.read_body()
将不起作用。那是对的吗?
感谢您的帮助。