Debugging Nginx Cache Misses: Hitting high number of MISS despite high proxy valid

Friscia, Michael michael.friscia at
Sat May 12 18:01:03 UTC 2018

I'm not sure if this will help, but I ignore/hide a lot, this is in my config

proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_hide_header X-Accel-Expires;
proxy_hide_header Pragma;
proxy_hide_header Server;
proxy_hide_header Request-Context;
proxy_hide_header X-Powered-By;
proxy_hide_header X-AspNet-Version;
proxy_hide_header X-AspNetMvc-Version;

I have not experienced the problem you mention, I just thought I would offer my config.


Michael Friscia

Office of Communications

Yale School of Medicine

(203) 737-7932 – office

(203) 931-5381 – mobile<>

From: nginx <nginx-bounces at> on behalf of Quintin Par <quintinpar at>
Sent: Saturday, May 12, 2018 1:32 PM
To: nginx at
Subject: Re: Debugging Nginx Cache Misses: Hitting high number of MISS despite high proxy valid

That’s the tricky part. These MISSes are intermittent. Whenever I run curl I get HITs but I end up seeing a lot of MISS in the logs.

How do I log these MiSSes with the reason? I want to know what headers ended up bypassing the cache.

Here’s my caching config


                proxy_set_header X-Real-IP  $remote_addr;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                proxy_set_header X-Forwarded-Proto https;

                proxy_set_header X-Forwarded-Port 443;

                # If logged in, don't cache.

                if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {

                  set $do_not_cache 1;


                proxy_cache_key "$scheme://$host$request_uri$do_not_cache";

                proxy_cache staticfilecache;

                add_header Cache-Control public;

                proxy_cache_valid       200 120d;

                proxy_hide_header "Set-Cookie";

                proxy_ignore_headers  "Set-Cookie";

                proxy_ignore_headers  "Cache-Control";

                proxy_hide_header "Cache-Control";

                proxy_pass_header X-Accel-Expires;

                proxy_set_header Accept-Encoding "";

                proxy_ignore_headers Expires;

                add_header X-Cache-Status $upstream_cache_status;

                proxy_cache_use_stale   timeout;

                proxy_cache_bypass $arg_nocache $do_not_cache;

- Quintin

On Sat, May 12, 2018 at 10:29 AM Lucas Rolff <lucas at<mailto:lucas at>> wrote:

It can be as simple as doing a curl to your “origin” url (the one you proxy_pass to) for the files you see that gets a lot of MISS’s – if there’s odd headers such as cookies etc, then you’ll most likely experience a bad cache if your nginx is configured to not ignore those headers.

From: nginx <nginx-bounces at<mailto:nginx-bounces at>> on behalf of Quintin Par <quintinpar at<mailto:quintinpar at>>
Reply-To: "nginx at<mailto:nginx at>" <nginx at<mailto:nginx at>>
Date: Saturday, 12 May 2018 at 18.26
To: "nginx at<mailto:nginx at>" <nginx at<mailto:nginx at>>
Subject: Debugging Nginx Cache Misses: Hitting high number of MISS despite high proxy valid


My proxy cache path is set to a very high size

proxy_cache_path  /var/lib/nginx/cache  levels=1:2   keys_zone=staticfilecache:180m  max_size=700m;

and the size used is only

sudo du -sh *

14M cache

4.0K    proxy

Proxy cache valid is set to

proxy_cache_valid 200 120d;

I track HIT and MISS via

add_header X-Cache-Status $upstream_cache_status;

Despite these settings I am seeing a lot of MISSes. And this is for pages I intentionally ran a cache warmer an hour ago.

How do I debug why these MISSes are happening? How do I find out if the miss was due to eviction, expiration, some rogue header etc? Does Nginx provide commands for this?

- Quintin

nginx mailing list
nginx at<mailto:nginx at><>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list