【发布时间】:2020-10-13 07:35:12
【问题描述】:
案例: 我有通过 HTTPS 的 REST API,我想在我的主机上配置一个基本的缓存代理服务来缓存 API 请求并像往常一样更快地获取相同的信息。
我的Nginx配置如下:
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:10m max_size=10g
inactive=60m use_temp_path=off;
http {
server {
location /my_api/ {
proxy_redirect off;
proxy_buffering on;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_ignore_headers Cache-Control;
proxy_cache my_cache;
proxy_pass https://example.com/myapi/;
}
}
}
现在我正在比较来自 REST API 和我的本地代理服务的响应时间,对于远程服务和本地代理服务的 REST API 调用与缓存相同,因此,这意味着缓存不起作用。 另外,缓存目录是空的。
对真实 API 的示例或请求(这不是真实案例):
curl "https://example.com/myapi/?key=1"
代理请求示例:
curl "http://127.0.0.1:8080/myapi/?key=1"
在 REST API 标头中我可以看到
cache-control: max-age=0, no-cache, no-store, must-revalidate
Nginx 可以忽略它吗?
我应该在代理配置中进行哪些更改才能看到 REST API 的提升? 我想知道这个问题是否与 HTTPS 流量有关?或者来自 REST API 的响应有一些 NoChaching 标头,或者响应的大小太小而无法缓存?
【问题讨论】:
标签: nginx caching nginx-config