Help with Location Directives needed

Hi,
i am having some troubles with location directives. As only the first
matching location directive is executed (if there is no rewrite of
course) i have to do a little hack to get my config to work. This
currently looks like this:

location ~ “^/(js|css|audio)/(.*)” {
add_header “Header1” “Value1”;
if ($args !~ ^$) {
add_header “Header1” “Value1”;
expires max;
}
}

location ~ “^/img/(.*)” {
if ($args !~ ^$) {
expires max;
}
}
this works for now :slight_smile:
what i actually only want to achieve:

  • set expires max for all files in img js css audio if some query params
    are set (in this case just some value for cache busting purposes)
  • set the Header1 if the file lies in js css audio

In this current config this is quite tricky as i have to set both
headers in seperatetly for every case.
Is there any way this config can be optimized? It would be really nice
if something like this would work:
location ~ “^/(js|css|audio|img)/(.*)” {
if ($args !~ ^$) {
expires max;
}
}

location ~ “^/(js|css|audio)/(.*)” {
add_header “Header1” “Value1”;
}

Any ideas?

Sebastian

Posted at Nginx Forum: