作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当使用 nginx fastcgi_cache 时,我缓存 HTTP 200 响应的时间比我缓存任何其他 HTTP 代码的时间都长。我希望能够根据此代码有条件地设置过期 header 。
例如:
fastcgi_cache_valid 200 302 5m;
fastcgi_cache_valid any 1m;
if( $HTTP_CODE = 200 ) {
expires 5m;
}
else {
expires 1m;
}
像上面这样的东西是否可能(在位置容器内)?
最佳答案
当然,来自 http://wiki.nginx.org/HttpCoreModule#Variables
$sent_http_HEADER
The value of the HTTP response header HEADER when converted to lowercase and
with 'dashes' converted to 'underscores', e.g. $sent_http_cache_control,
$sent_http_content_type...;
所以你可以在 if 语句中匹配 $sent_http_response
尽管自 http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires 以来还是有问题的没有将 if 列为 expires 指令的允许上下文
您可以解决在 if block 中设置变量的问题,然后像这样稍后引用它:
set $expires_time 1m;
if ($send_http_response ~* "200") {
set $expires_time 5m;
}
expires $expires_time;
关于caching - nginx:将条件过期 header 添加到 fastcgi_cache 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942677/
有没有内置的方法可以用 PHP 清除 Nginx fastcgi_cache?我知道我可以编写一个 PHP 脚本来手动删除所有缓存文件,但这似乎太像黑客了。 最佳答案 如果你有 fastcgi_cac
当使用 nginx fastcgi_cache 时,我缓存 HTTP 200 响应的时间比我缓存任何其他 HTTP 代码的时间都长。我希望能够根据此代码有条件地设置过期 header 。 例如: fa
我是一名优秀的程序员,十分优秀!