V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
kokol
V2EX  ›  NGINX

nginx 的 cache file has too long header 问题

  •  
  •   kokol · Oct 20, 2020 · 3603 views
    This topic created in 2017 days ago, the information mentioned may be changed or developed.
    有时在 nginx 的日志里会碰到如下的日志错误:

    cache file "/usr/local/openresty/nginx/cache/c/0c/1eb7633e809b8306294a2a7da39c80cc" has too long header

    一般什么情况下,才会出现这个错误,我的 proxy_buffer_size 这些设置都是用的默认值。

    google 搜索了一下,看到 nginx 的源代码里有如下的代码:
    https://github.com/phusion/nginx/blob/master/src/http/ngx_http_file_cache.c
    if (h->body_start > c->body_start) {
    ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
    "cache file \"%s\" has too long header",
    c->file.name.data);
    return NGX_DECLINED;
    }

    http://hg.nginx.org/nginx/rev/6f97afc238de 这个网站也有相应的说明

    我自己也测试了一下,proxy_buffer_size 这些设置都是用的默认值,然后请求一个 2M 的文件,proxy_cache 的文件夹里也有缓存的文件,但是访问都是正常的,我还是无法复现这种错误,不知道什么情况下会出现这个错误
    2 replies    2020-10-22 11:17:20 +08:00
    geekzu
        1
    geekzu  
       Oct 21, 2020
    之前遇到过,查了一圈应该是 cache 文件失效 /损坏导致,这种状态 nginx 会重新取源做新的 cache
    kokol
        2
    kokol  
    OP
       Oct 22, 2020
    @geekzu 谢谢,我用 ab 压测工具压测了下,有个上千并发的时候,就会有 cache file has too long header 的错误
    如果 nginx 响应的 body 比较大的时候,出现的概率也大。

    难道是在高并发情况下,nginx 从后端获取到文件之后,放入了一部分到缓存文件里,另一个请求过来发现文件不完整就重新去后端请求
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4233 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:59 · PVG 17:59 · LAX 02:59 · JFK 05:59
    ♥ Do have faith in what you're doing.