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;
}
3
  • That sounds like you're looking to use the http rewrite module to rewrite certain requests...
    – HBruijn
    Oct 27, 2015 at 20:58
  • Update should work. Though I would use $arg_baz = quux
    – Alexey Ten
    Oct 27, 2015 at 21:36
  • @AlexeyTen yes actually it works. And thanks for pointing out to $arg_baz.
    – Kolyunya
    Oct 27, 2015 at 21:55

1 Answer 1

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;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .