在 ubuntu 12.10 上运行 nginx 1.4.1
需要根据 http 响应的 MIME 类型/内容类型有条件地发送过期标头。
在 location / { 中添加了这段简单的代码
if ($sent_http_content_type = "text/css") {
expires 7d;
}
Run Code Online (Sandbox Code Playgroud)
即使 $sent_http_content_type 包含“text/css”,也不会发送 expires 标头
如何解决这个问题?
检查文件扩展名是不够的,因为在我的应用程序 js、css 中,图像是从 php 动态生成的。所以需要检查 mime 并添加基于它的标题。
nginx ×1