Forum: NGINX nginx can not cache

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
55c8faf296304dde6370e7d9e6b1fcc9?d=identicon&s=25 weichenqi (Guest)
on 2009-05-18 08:46
(Received via mailing list)
Hi,
   I want to cache static files as gif,jpg and so on .that my config
files:

location *~*\.(jgp|gif|png|css|swf|html|htm)$ {
        root /web/html/;
        proxy_store on;
        proxy_set_header Accept-Encoding '';
        proxy_temp_path /web/tmp/;
        proxy_store_access user:rw group:r all:r;
        if (!-f $request_filename)
        {
        proxy_pass http://localhost:81;
}
}
        location / {
               proxy_redirect off;
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
               client_max_body_size 50m;
               client_body_buffer_size 256k;
               proxy_connect_timeout 30;
               proxy_send_timeout 30;
               proxy_read_timeout 60;
               proxy_buffer_size 4k;
               proxy_buffers 4 32k;
               proxy_busy_buffers_size 64k;
               proxy_temp_file_write_size 64k;
               proxy_next_upstream error timeout invalid_header http_500
http_503 http_404;
               proxy_max_temp_file_size 128m;

               proxy_store off;

                   proxy_pass http://test/;
          }
}
}
now,it have problem,inthe proxy_temp_path /web/tmp/
there is no files cache.why?thanks!
2009-05-18



weichenqi
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-20 11:08
(Received via mailing list)
On Mon, May 18, 2009 at 02:36:15PM +0800, weichenqi wrote:

>         {
>                proxy_connect_timeout 30;
>
>                    proxy_pass http://test/;
>           }
> }
> }
> now,it have problem,inthe proxy_temp_path /web/tmp/
> there is no files cache.why?thanks!

First,

-location *~*\.(jgp|gif|png|css|swf|html|htm)$ {
+location ~* \.(jgp|gif|png|css|swf|html?)$ {

Second, instead of

   if (!-f $request_filename) {
       proxy_pass http://localhost:81;
   }

you should use

location ~* \.(jgp|gif|png|css|swf|html?)$ {
        root /web/html/;
        try_files  $uri  @fetch;
}

location @fetch {
        proxy_pass http://localhost:81;
        proxy_set_header Accept-Encoding '';
        proxy_store on;
        proxy_store_access user:rw group:r all:r;
        proxy_temp_path /web/tmp/;
        root /web/html/;
}
This topic is locked and can not be replied to.