Setting expires header bypasses app server

Michael Shadle mike503 at
Wed Apr 1 21:06:28 MSD 2009

On Wed, Apr 1, 2009 at 3:34 AM, nmk <nginx-forum at> wrote:

>    if (!-f $request_filename) {
>      proxy_pass http://thins;
>      break;
>    }
>    location ~* \.(js|css|jpg|jpeg|gif|png)$ {
>      if (-f $request_filename) {
>        expires      max;
>        break;
>      }
>    }
>  }
> When request /javascripts/foo.js on the production app (hitting nginx) a 404 is returned directly instead if the request being passed to the app servers. I would expext the request to be passed to the app servers as the file is not on the filesystem. Why doesn't the !-f $request_filename condition (lines 15-18) apply?
> If I remove the last portion of the nginx config file (the one which adds an expires header to static files) all works as expected.
> Any idea what might be wrong?

It's because it is matching that regexp first.

You could do your if (-f ) check inside of there and it would probably
work, but that's kind of messy. I'm sure Igor can post and give you a
much cleaner way to do the entire thing. Location blocks confuse the
hell out of me sometimes.

More information about the nginx mailing list