4 messages in ru.sysoev.nginxRe: proxy with caching functionality
FromSent OnAttachments
Martin MinkaMay 10, 2007 1:35 am 
RoxisMay 10, 2007 2:34 am 
Evan MillerMay 10, 2007 9:55 am 
Igor SysoevMay 10, 2007 3:15 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: proxy with caching functionalityActions...
From:Evan Miller (emmi@public.gmane.org)
Date:May 10, 2007 9:55:26 am
List:ru.sysoev.nginx

Martin Minka <martin.minka@...> writes:

I have question about caching functionality in nginx.

The purpose is to use nginx on local server to speed up responses from <remote server>. 1. Will the following configuation cache static content from <remote server> for 5d ? 2. Where will the cached content be stored ? Directory ../nginx/proxy_temp is always empty.

"expires" just refers to how long items will remain in the browser cache.

Nginx cannot act as a caching proxy. There are a couple of ways to emulate caching behavior if you control the remote server. One is to have the remote server stuff its results in Memcached. See http://wiki.codemongers.com/NginxMemcachedModule. Another solution is for the remote server, upon receiving a request from Nginx, to send a PUT request to Nginx where Nginx will find the file in the future, then reply to the initial request with X-Accel-Redirect to the newly PUTted file. I do this for some image files I want to dynamically resize and cache. My nginx.conf looks like:

location /images { include conf/fastcgi_params;

if (!-f $request_filename) { fastcgi_pass backend; }

dav_methods put; create_full_put_path on;

limit_except GET { allow 192.168.0.0/16; allow 127.0.0.1/32; deny all; }

expires max; }

The advantages over the Memcache method is that MIME types will work out of the box, the disk cache doesn't expire, and it's often faster.

Hope this helps.

Evan

location ~*

^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|css|doc|xls|exe| pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|xml)$

{ include conf/mime.types;

proxy_pass http://<remote server>;

proxy_redirect off;

access_log logs/access.static.log; expires 5d; }

Martin Minka