proxy_cache with document root

cripy ccripy at
Thu Nov 12 01:29:07 MSK 2009

Hello all,

We have a situation where we have a document root that is a network
filesystem.  We'd like to use Nginx to cache data locally to offload
some load from the network filesystem.  For our particular situation
Nginx would not sit in the front but rather in the back because we
have an auth layer that authenticates a user before sending the file.

A client would hit the auth layer first(apache) which would then
reverse proxy to Nginx which would serve up the file.

The issue we have run into is we can't get proxy_cache to work without
a proxy_pass statement.  We'd like to avoid creating a new local vhost
to handle this.

We're basically looking for a way to setup a vhost in Nginx that uses
proxy_cache but instead of using a "remote http resource" it would use
the document root.

This way it would only send a file from the document root(network
filesystem) only if it didn't have the file in cache.

Below is are the proxy part of the configurations(stripped the rest of
the conf out but it is all default) we are working with.

It works fine when I run a virtual host on another port(81) and use
proxy_pass (as shown commented below)...but I would prefer it to just
read straight from the document root and not use proxy_pass to a
network resource.

Any help is greatly appreciated!  Thanks.

http :

    proxy_buffer_size 16k;
    proxy_buffers 8 16k;
    proxy_buffering on;
    proxy_busy_buffers_size 32k;
    proxy_max_temp_file_size 0;
    proxy_intercept_errors on;
    proxy_cache_path  /data/cache  levels=1:2 keys_zone=one:200m inactive=3d;
    proxy_temp_path  /data/temp;
    proxy_cache_valid  200 5d;
    proxy_cache_valid 302 1m;
    proxy_cache_valid 404 1m;
    proxy_cache_min_uses 30;
    proxy_ignore_client_abort on;
    proxy_headers_hash_max_size 4096;


    location / {
        root /usr/sites/;
        index index.html;
#        proxy_pass http://localhost:81
        proxy_cache one;


More information about the nginx mailing list