Take the 2-minute tour ×
Server Fault is a question and answer site for 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

locked by HopelessN00b Feb 20 at 5:42

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as off-topic by HopelessN00b Feb 20 at 5:42

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance. –  HopelessN00b Feb 20 at 5:42

2 Answers 2

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

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

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