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 am using rewrite like this

    if (!-e $request_filename) {
            rewrite ^/(en|ga)?/?(.*)$ /index2.php?cultureKey=$1&mq=$2 last;
    }

but after I need certain rewritten URLs to be cached for 30 seconds. Remaining fast_cgi requests should be 5 minutes.

    fastcgi_cache_valid   200 302  5m;

    expires 5m;
    if ($args ~* (dynamic\.html)){
        expires 30s;
    }

I have tried moving those around, but either both dynamic.html and other files are still cached after 30 seconds or they both expire after 30.

How to make dynamic.html (rewritten) cached for 30s and remaining files for 5m?

thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

$args is a variable containing the request parameters on a GET, are you sure you are not after $request_uri or $uri? Maybe using a location block is better:

location ~* dynamic.html {
    expires 30s
}

but it depends on the rest of your config so YMMV.

share|improve this answer
    
how exactly config works? if i specify expires twice, which one is used? –  romaninsh Apr 8 '11 at 5:54
    
and i have $args after rewrite. –  romaninsh Apr 8 '11 at 5:55
    
From what I know from Nginx configuration, the most specific applies before the broader, so I think that the 30s rule will apply to the ones that match the location and the others will be matched by the outside expires of 5m, but I can't find any documentation to back me there. About your other question, you should read this and this on nginx docs to understand. –  coredump Apr 8 '11 at 6:01

I think it is 'if' what causing problems. You should read this http://wiki.nginx.org/IfIsEvil

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.