0

We have a legacy application written in php which we are now migrating to java. The Application being hige, we are trying to migrate features in part. Keeping this scenario in mind, i need to split traffic between php-fpm backend and the java app based on the value of a query string argument

for eg if $format="csv", use fast-cgi and process request using php If $format="xml",connect to the java backend using the proxy_pass directive.

Unfortunately i am finding it difficult to do this on nginx.

I tried the following

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

here php and proxy are files containing the proxy_pass and fast-cgi related statements

Unfortunately this throws a syntax error

Then I create a map by using something like

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

then did an include $provider;

This also fails as nginx seems to load the includes at start time and not during execution of each call.

Any suggestions on how i can achieve this in an elegant way.

Sanket Gupta
  • 573
  • 3
  • 6
  • 21

1 Answers1

0

The variable name is $arg_format http://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_

You must use { } after if statement. http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if

Try something like ...

if ($arg_format ="csv") {
 include php;
}
if ($arg_format ="xml") {
 include proxy;
}
ways
  • 306
  • 1
  • 3
  • we cannot have an include inside an if condition.If is executed at run time while an include seems to happen when the config file is being parsed. – Sanket Gupta Jul 21 '14 at 08:21