proxy with caching functionality

Evan Miller emmiller+gmane at
Thu May 10 20:55:49 MSD 2007

Martin Minka <martin.minka at ...> 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 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 {
                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.


> location ~* 

> {                        
> include       
> conf/mime.types;     
> proxy_pass http://<remote 
> server>;          
> proxy_redirect          
> off;           
> access_log   
> logs/access.static.log;                        
> expires      
> 5d;                
> }              
> Martin 
> Minka

More information about the nginx mailing list