Skip Location Based On Query String Parameter?

nrahl nginx-forum at nginx.us
Thu Nov 13 11:20:05 UTC 2014


We'd like to bypass a location if a query string varaible is present. Is
this an approriate place to use "if", and if so, how should it be done? If
the URL is a forward slash, followed by anything, followed by a forward
slash, it attempts to find a static html.gz file in the cache folder
matching the url, and then passes it to apache. This is the desired
behavior, except when the URL contains ?nocache=true. If the nocache
parameter is present, it should skip the cache check and go straight to the
proxy pass.

This is the config we're using now:

   location ~ ^/([a-zA-Z0-9\-]+)/ { #Use cache if possible, then proxy pass
      try_files /cache/$1.html.gz /cache/$1.html @apache;
   }

   location / { 
      include /etc/nginx/apache-pass;
   }

   # Pass the PHP script to AquaCart
   location @apache {
      include /etc/nginx/apache-pass;
   }

What's the correct way to bypass the ^/([a-zA-Z0-9\-]+)/ location when a
specific query string parameter is set?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,254800,254800#msg-254800



More information about the nginx mailing list