gpt4 book ai didi

linux - nginx 作为缓存代理不缓存任何东西

转载 作者:IT王子 更新时间:2023-10-29 00:20:04 26 4
gpt4 key购买 nike

我正在尝试缓存静态内容,这些内容基本上位于虚拟服务器配置中的以下路径内。由于某些原因,文件没有被缓存。我在缓存目录中看到了几个文件夹和文件,但它总是大约 20mb 不高不低。例如,如果它缓存图像,则至少需要 500mb 的空间。

这里是 nginx.conf 缓存部分:

** nginx.conf **
proxy_cache_path /usr/share/nginx/www/cache levels=1:2 keys_zone=static$
proxy_temp_path /usr/share/nginx/www/tmp;
proxy_read_timeout 300s;

这是默认的虚拟服务器。

**sites-available/default**
server {
listen 80;

root /usr/share/nginx/www;
server_name myserver;
access_log /var/log/nginx/myserver.log main;
error_log /var/log/nginx/error.log;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location ~* ^/(thumbs|images|css|js|pubimg)/(.*)$ {
proxy_pass http://backend;
proxy_cache static;
proxy_cache_min_uses 1;
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
expires max;
}

location / {
proxy_pass http://backend;
}
}

最佳答案

确保您的后端不返回 Set-Cookie header 。如果 Nginx 看到它,它会禁用缓存。

如果是这种情况,最好的选择是修复后端。当无法修复后端时,可以指示 Nginx 忽略 Set-Cookie header

proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";

参见 documentation

proxy_ignore_header 将确保缓存发生。 proxy_hide_header 将确保 Cookie 负载不包含在缓存的负载中。这对于避免通过 NGINX 缓存泄漏 cookie 很重要。

关于linux - nginx 作为缓存代理不缓存任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9230812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com