nginx - 为什么nginx不缓存?
问题描述
我正在使用以下 nginx 配置来缓存 s3 响应,我能够访问 s3,但无法缓存任何内容。不知道为什么!
proxy_cache_path /var/cache/nginx
levels=1:2 keys_zone=s3_cache:1024m max_size=250g
loader_files=150000 loader_threshold=1s loader_sleep=50ms
inactive=365d use_temp_path=off;
location / {
# Calling aws_auth, to set HTTP Headers
set $s3_host s3.amazonaws.com;
set $s3_uri "/$arg_bucket$uri";
access_by_lua "local aws = require 'resty.aws_auth'; aws.s3_set_headers(ngx.var.s3_host, ngx.var.s3_uri)";
resolver ...;
# Cache related settings
proxy_cache s3_cache;
proxy_cache_valid 200 30d; # 1 month
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_bypass $http_cache_purge;
# disable convert get to head, otherwise, HEAD request will be denied
proxy_cache_convert_head off;
# disable cache convert requires setting cache key, $request_method is not part of proxy_cache_key by default
proxy_cache_methods GET HEAD;
proxy_cache_key $scheme$request_method$proxy_host$s3_uri;
# This max-age is different from "inactive" in proxy_cache_path.
# It tells the browser or intermediary cache how long the response can be used from the time it was requested.
add_header Cache-Control max-age=2592000;
add_header X-Cache-Status $upstream_cache_status;
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid
# make sure the response will be cached.
proxy_ignore_headers Set-Cookie Vary;
proxy_pass https://$s3_host$s3_uri;
}
}
error/access.log 没有说系统有任何问题。不确定我是否遗漏了什么。
解决方案
在http
级别有proxy_buffering off
,删除该行后,它开始缓存。
不幸的是,没有errors.log
关于此的错误或文档。
推荐阅读
- c# - 为什么我得到“最好的重载列表
集合初始值设定项的 add 方法有一些无效参数” - html - Why doesn't container take up entire height
- list - Flutter switch button not updating
- javascript - What should be structure of service layer in Node.js
- google-cloud-platform - intermittent 401 from google cloud build api Oauth issues
- excel - Vba Excel: Userform closing by itself on End Sub
- algolia - Vue-InstantSearch (Algolia): How to add ref= to input field?
- android - How to handle links that open in new tabs in react native web view?
- flutter - TabView does not preserve state when swiping from one tab to another
- flutter - Responsive Column to Row depending on content size