Nginx expire dates for static files

If you are using nginx as proxy this snippet will help you set the correct expire dates for static files like css, jpg etc:

[code]location ~* \.(txt|xml|js)$ {
expires 8d;
}

location ~* \.(css)$ {
expires 8d;
}

location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$ {
expires 8d;
}

location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
expires 8d;
}[/code]

This is will ensure the webserver to tell the browser that the served files are valid for 8 days and will not be downloaded again.

Published by

Maarten Keizer

Hosting guru. WordPress addict. n00b programmer.

Leave a Reply

Your email address will not be published. Required fields are marked *