Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following

location ~ "/foo/(.+)\.\w{3}$" {
  alias /srv/DM/pictures/store/$1;
}

That does exactly what I want, with one small exception. If there is a query keyword appended to the location I want it to not-match:

MATCH: http://foo/bar.jpg
NO: http://foo/bar.jpg?s_thumb
NO: http://foo/bar.jpg?large_thumb

Any ideas on how to go about accomplishing this?

share|improve this question

3 Answers 3

This is not possible as locations will only match against the URI without query parameters. You'll need to use an if inside the location along with http://wiki.nginx.org/HttpCoreModule#.24arg_PARAMETER

if ($is_args) {
    break;
}
share|improve this answer
    
What do I place in the if after I test for parameters? –  Evan Carroll Feb 21 '11 at 19:54
    
@EvanCarroll I edited my answer to provide an example that would work. –  Martin Fjordvald Feb 21 '11 at 21:23

Regex based locations are matched procedurally, meaning that the matching depends on the order in which they appear in the config file.

Place an if block inside the location and do whatever you want when it's not matching, i.e., it has the query string:


if ($is_args) {
 (do something else...)
}
share|improve this answer
    
What do I place in the if after I test for parameters? –  Evan Carroll Feb 21 '11 at 19:55

This is the method that I finally got working. You can't simply place the alias inside of the if statement. But, you can use an internal redirect

server {

  ...;

  location /_image {
    internal;
    alias /srv/DM/pictures/store/;
  }

  location / {

    ...;

    if ( $args = '' ) {
      rewrite "/image/(.*)\.\w{3}$" /_image/$1 last;
    }

    ...;

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.