繁体   English   中英

Nginx:根据参数值使用不同的后端

[英]Nginx: Use different backend based on value of argument

我们有一个用php编写的旧应用程序,现在正在迁移到Java。 由于应用程序比较庞大,我们正在尝试部分迁移功能。 记住这种情况,我需要根据查询字符串参数的值在php-fpm后端和Java应用程序之间分配流量

例如,如果$ format =“ csv”,则使用fast-cgi并使用php处理请求;如果$ format =“ xml”,则使用proxy_pass指令连接到Java后端。

不幸的是,我发现在nginx上很难做到这一点。

我尝试了以下

if ($args_format ="csv")
 include php;
if ($args_format ="xml")
 include proxy;

这里的php和proxy是包含proxy_pass和fast-cgi相关语句的文件

不幸的是,这引发了语法错误

然后我使用类似的方法创建地图

map $args_output $provider {
  default "proxy";
  csv      "php";
}

然后做了一个include $ provider;

这也失败了,因为nginx似乎在开始时而不是在每个调用执行期间加载include。

关于如何以一种优雅的方式实现这一目标的任何建议。

变量名称为$ arg_format http://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_

您必须在if语句后使用{}。 http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if

尝试类似...

if ($arg_format ="csv") {
 include php;
}
if ($arg_format ="xml") {
 include proxy;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM