static files and 404

Cliff Wells cliff at develix.com
Thu Mar 19 23:21:25 MSK 2009


On Thu, 2009-03-19 at 20:14 +0200, Marcelo Barbudas wrote:
> Hi,
> 
> I have a setup where I am using nginx with RubyOnRails.
> 
> The setup looks simple:
> if (!-f $request_filename) {
>   proxy_pass http://domain1;
>   break;
> }
> 
> However I have a directory that holds images that sometimes get deleted.
> People keep linking to those images and the 404s go to the rails process.
> 
> How can I tell nginx that any request towards:
> /images/subassets/*.gif
> should never be forwarded to rails?

location ~ /images/subassets/*.gif { 
  root /path/to/root; 
}

location / {
  root /path/to/root;
  error_page 404 = @rails;
}

location @rails {
  proxy_pass http://domain.com;
}

If you don't want *anything* from the subassets folder (not just gifs)
to be passed to Rails, then just use

location /images/subassets {
  root /path/to/root;
}

Cliff







More information about the nginx mailing list