Skip Location Based On Query String Parameter?

nrahl nginx-forum at
Sun Jan 4 14:12:40 UTC 2015

> It would need testing, and it does depend on what is in the
> "apache-pass"
> file, but presuming that it does do "proxy_pass" and does not do
> anything
> that is invalid in an "if in location", then
> >    location ~ ^/([a-zA-Z0-9\-]+)/ { #Use cache if possible, then
> proxy pass
>        if ($arg_nocache = true) {
>          include /etc/nginx/apache-pass;
>        }
> >       try_files /cache/$1.html.gz /cache/$1.html @apache;
> >    }
> could possibly work.

When trying to use if(){include} I get the error, "'include' directive is
not allowed here", I guess include itself is one of those things not allowed
in an if statement? I found another post on the board that says "if" isn't
allowed in include because they are both block directives and no one wants
to fix it because "if" is a hack anyway.

Maybe it can be done by using a nested location blocks, something like:

location (!$arg_nc) { # the qs parameter "ns" does not exist
   location ~ ^/([a-zA-Z0-9\-]+)/ {
      try_files /cache/$1.html @apache;

Posted at Nginx Forum:,254800,255948#msg-255948

More information about the nginx mailing list