Nginx doesn't cache as expected

davide.damico nginx-forum at nginx.us
Fri Aug 21 14:27:54 MSD 2009


Hi, I'm using nginx as a reverse proxy and I'd like to locally cache files to serve them rather than pass the request to backend servers.
I'm using FreeBSD 7.0 i386 and nginx-0.7.61_1.

I'm using this configuration block:

upstream 1_2_4_backend  {
  server 172.16.7.121:80;
  server 172.16.7.122:80;
  server 172.16.7.124:80;
}

server {
  server_name blog.leiweb.it;
  listen 172.16.7.130:80;
  access_log    /var/log/nginx/blog_leiweb.log;

  location / {
    proxy_redirect     off;
    proxy_pass           http://1_2_4_backend;
    proxy_store_access   user:rw  group:rw  all:r;
    proxy_temp_path      /usr/local/tmp;
    proxy_store /usr/local/www_ng/$uri#;
    proxy_cache_valid  200 10m;
    proxy_set_header Host $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

/usr/local/www_ng/ is populated but if I request a file (http://blog.leiweb.it/moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg) I see the request always being redirected to backend servers also if /usr/local/www_ng/moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg# is present (yes, I copied moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg# to moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg to see if it was a '#' problem, but nginx had the same behaviour).

Here the header content while grabbing that url using curl:

>From a backend server:
davide:~ dave$ curl -L -v http://blog.leiweb.it/moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg
* About to connect() to blog.leiweb.it port 80 (#0)
*   Trying 172.16.7.124... connected
* Connected to blog.leiweb.it (172.16.7.124) port 80 (#0)
> GET /moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg HTTP/1.1
> User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
> Host: blog.leiweb.it
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 21 Aug 2009 10:24:45 GMT
< Server: Apache
< X-Powered-By: PHP/5.2.6
< Content-Length: 25319
< Last-Modified: Fri, 07 Aug 2009 15:35:08 GMT
< ETag: "d53c497dc843b21b709173cfebffc07b"
< Expires: Sun, 21 Oct 2012 20:11:25 GMT
< X-tmt: D=37410 t=1250850285373708 | Q
< Connection: close
< Content-Type: image/jpeg
< 
????JFIF??;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90

-----------------------------------------------------------
>From nginx:
davide:~ dave$ curl -L -v http://blog.leiweb.it/moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg
* About to connect() to blog.leiweb.it port 80 (#0)
*   Trying 213.92.90.43... connected
* Connected to blog.leiweb.it (213.92.90.43) port 80 (#0)
> GET /moda/files/2009/08/big_20090716_raphaelyoung2-460x304.jpg HTTP/1.1
> User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
> Host: blog.leiweb.it
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/0.7.61
< Date: Fri, 21 Aug 2009 10:25:17 GMT
< Content-Type: image/jpeg
< Connection: keep-alive
< X-Powered-By: PHP/5.2.6
< Content-Length: 25319
< Last-Modified: Fri, 07 Aug 2009 15:35:08 GMT
< ETag: "d53c497dc843b21b709173cfebffc07b"
< Expires: Sun, 21 Oct 2012 20:11:57 GMT
< X-tmt: D=40133 t=1250850317805289 | U
< 
????JFIF??;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90

Thanks in advance,
d.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,5081,5081#msg-5081






More information about the nginx mailing list