我正在使用以下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没有说系统有任何问题。不知道我是否想念什么。
答案 0 :(得分:0)
在http
级别有proxy_buffering off
,在删除该行之后,它开始进行缓存。
很遗憾,errors.log
或与此相关的文档中没有错误。