Help with Location Directives needed

tmsmaster nginx-forum at nginx.us
Fri Sep 10 13:52:19 MSD 2010


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 :)
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: http://forum.nginx.org/read.php?2,129102,129102#msg-129102




More information about the nginx mailing list