Nginx caching based on file type

cachenginx

I'm using Nginx to serve my static files and proxy dynamic requests to Django. I'd like to cache the static files ("expires 24h;") for all static files except those ending with *.swf.

When I was using Apache, I placed this in the .htaccess file of the directory containing the *.swf files and it worked great:

<FilesMatch "\.(swf)$">
Header set Cache-Control "no-cache"
</FilesMatch>

How can I achieve a similar result in my Nginx config?

Best Answer

Using location directive with appropriate regex and with expires directive should work:

location ~ \.(swf)$ {
    expires -1;
}