nginx cache issue (http upstream cache: -5)

loopback_proxy nginx-forum at
Mon Feb 5 09:08:33 UTC 2018

I am new to nginx caching but have worked with nginx a lot. I tried enabling
caching feature in our repository but it never worked so I thought I will
pull a fresh copy of nginx and turn it on. I ended with the same issue. For
some reason, nginx is not able to create the cache file in the cache dir.  I
have already turned on proxy buffering and set full rw permission for all
users on the cache dir. I also gdb'ed the code and it seems like it gets
into ngx_open_and_stat_file from ngx_open_cached_file (
) and it tries to open an non existent file in RDONLY mode if the of->log is
not set (

Any help here would be awesome.  I have also pasted my relevant config and
debug log below. 

Here's my configuration.. (only the relevant part)

http {

    proxy_cache_path  /tmp/nginx/cache  levels=1:2    keys_zone=STATIC:10m
    inactive=24h  max_size=1g;

    server {
        listen       80;
        server_name  localhost;
        proxy_buffering on;

        location / {
            proxy_set_header Host;
	    proxy_buffering on;
            proxy_cache            STATIC;
	    add_header X-Proxy-Cache $upstream_cache_status;
            root   html;
            index  index.html index.htm;

And here's the debug log showing whats that nginx is failing to create the
cache file. 
2018/02/05 08:57:26 [debug] 22509#0: *7 http cache key:
2018/02/05 08:57:26 [debug] 22509#0: *7 http cache key:
2018/02/05 08:57:26 [debug] 22509#0: *7 add cleanup: 00000000006D3560
2018/02/05 08:57:26 [debug] 22509#0: shmtx lock
2018/02/05 08:57:26 [debug] 22509#0: slab alloc: 120 slot: 4
2018/02/05 08:57:26 [debug] 22509#0: slab alloc: 00007FD2C31AA080
2018/02/05 08:57:26 [debug] 22509#0: shmtx unlock
2018/02/05 08:57:26 [debug] 22509#0: *7 http file cache exists: -5 e:0
2018/02/05 08:57:26 [debug] 22509#0: *7 cache file:
2018/02/05 08:57:26 [debug] 22509#0: *7 add cleanup: 00000000006D35B0
2018/02/05 08:57:26 [debug] 22509#0: *7 http upstream cache: -5

And for now i have set "777" perm to the nginx cache dir. 

>> ls -lrt /tmp/nginx/                                                      
drwxrwxrwx 2 test root 4096 Feb  5 08:20 cache

Posted at Nginx Forum:,278346,278346#msg-278346

More information about the nginx mailing list