I\'m looking for a way to set server wide expires headers so that all existing or new virtual hosts will be configured the same. Unfortunately, I can not do this in each virtua
The expires directive can be placed in the http block and is therefore inherited by all server blocks and their location blocks.
The manual shows an example of using the expires directive with a map variable. See this document.
You could use $request_uri rather than $sent_http_content_type to match your existing regex and achieve identical behaviour with:
map $request_uri $expires {
default off;
~*\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)(\?|$) max;
}
expires $expires;
Both directives placed inside the http block but outside any server block.
See this document for details.