Welcome! Log In Create A New Profile

Advanced

proxy_cache not working as expected

Posted by d.freudenberger 
proxy_cache not working as expected
August 29, 2012 12:51PM
Hi there,

I'm trying to setup the proxy cache for one of our services. So far I've got following config file

upstream content-service {
server 10.55.1.11:7010;
server 10.55.1.12:7010;
server 10.55.1.13:7010;
}

proxy_cache_path /opt/nginx/cache/content levels=1:2 keys_zone=content-cache:1000m max_size=1000m inactive=24h;

server {
location / {
proxy_cache content-cache;
proxy_cache_valid 24h;
proxy_cache_use_stale updating;
proxy_pass http://content-service;
proxy_set_header X-Real-IP $remote_addr;
}
}

I can see that nginx writes cached entries to the specified directory (/opt/nginx/cache/content). But even if a cached record exists, nginx sends *each* request to the upstream server instead of serving the content from cache. I know there are some circumstances which prevent nginx from delivering cached content (like set-cookie etc). I think that no criteria for non-cacheable responses is met. Just to be sure, here's one sample request/response

curl -v https://.../product/1829201

> GET /product/1829201 HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: ...
> Accept: */*

< HTTP/1.1 200 OK
< Server: nginx/1.0.15
< Date: Wed, 29 Aug 2012 16:47:09 GMT
< Content-Type: application/json
< Connection: keep-alive
< Content-Length: 2900
< X-Foo-Service: ContentService
< X-Foo-Version: 1.0
< X-Foo-UUID: ContentService_503dbf10389fd
< X-Foo-Status: successful

{...}

The cached record looks like this:

cat 1/0f/b74a7cf47c9bcd6294846b63e8fb30f1

??P?????????=Pn?P?UmX:?ZP
KEY: http://content-service/product/1829201
HTTP/1.0 200 OK
Date: Wed, 29 Aug 2012 07:04:48 GMT
Server: nanoserv/2.1.0
Content-Type: application/json
Content-Length: 2900
X-Foo-Service: ContentService
X-Foo-Version: 1.0
X-Foo-UUID: ContentService_503dbf10389fd
X-Foo-Status: successful
Connection: Close

{...}

Right now I'm running nginx version: nginx/1.0.15 - I know it's not the latest version but I haven't seen anything related to proxy_cache in the changelogs.

Any help is highly appreciated.

Best regards,
Daniel
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 164
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready