0

I would like to serve data on one and the same host from different directories depending on a query parameter using Nginx.

For example https://foo.bar/index.html should be served from /var/www/foo and https://foo.bar/index.html?baz=quux from /var/www/bar.

I've tried to change the server root conditionally, but it turns out it's not supported.

root /var/www/foo;    
if ($args ~ baz=quux) {
    # this is not gonna work but that is what is needed
    # root /var/www/bar;
}
Kolyunya
  • 217
  • 1
  • 3
  • 9

1 Answers1

0

I'm not sure if it is the most elegant way to solve the problem, but using a variable in root directive works as expected.

set $env 'foo';
if ($arg_baz=quux) {
    set $env 'bar';
}
root /var/www/$env;
Kolyunya
  • 217
  • 1
  • 3
  • 9