NGINX - How would I set expires headers for all virtual hosts?

前端 未结 1 1953
灰色年华
灰色年华 2021-01-25 02:53

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

相关标签:
1条回答
  • 2021-01-25 03:29

    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.

    0 讨论(0)
提交回复
热议问题