1

I have this in my nginx config:

nginx.conf, http section:

proxy_cache_path /var/tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=600m use_temp_path=off;
proxy_buffering on;

Then in my site's config I have this section:

location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
        proxy_cache my_cache;
        proxy_cache_revalidate on;
        proxy_cache_min_uses 1;
        proxy_pass http://my.backend;
        add_header X-Cache-Status $upstream_cache_status;
}

Whenever I make a request NGINX responds with

X-Cache-Status: MISS

header. Example response:

HTTP/1.1 200 OK
Server: nginx/1.13.8
Date: Mon, 12 Feb 2018 08:32:47 GMT
Content-Type: application/javascript 
Content-Length: 40802
Connection: keep-alive 
Last-Modified: Sun, 11 Feb 2018 06:31:40 GMT
ETag: "9f62-564e9ea066b00" 
Vary: Accept-Encoding 
X-Cache-Status: MISS
Accept-Ranges: bytes

And the same request to my backend:

HTTP/1.1 200 OK 
Date: Mon, 12 Feb 2018 08:22:32 GMT 
Server: Apache/2.4.7 (Ubuntu) 
Last-Modified: Sun, 11 Feb 2018 06:31:40 GMT
ETag: "9f62-564e9ea066b00" 
Accept-Ranges: bytes
Content-Length: 4080
Vary: Accept-Encoding 
Content-Type: application/javascript

What have I missed?

1
  • Just for clarification, this is not static files for nginx.
    – Alexey Ten
    Feb 12, 2018 at 20:55

1 Answer 1

2

I'm not yet eligible to commenting so I'll use an answer instead:

Your config looks fine so far.

  1. Is /var/tmp/nginx_cache writeable for your nginx user?

  2. You mentioned 'whenever I make a request'. But you made several requests in row, right? As the first request will always be a MISS as long as resource isn't in the cache, yet.

  3. Try adding:

    proxy_cache_key $host$uri$is_args$args;
    proxy_cache_valid 200 10m;
    

BTW, the ^.+ part in your location regex seems to be redundant.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .