Setting expires header bypasses app server

nmk nginx-forum at
Wed Apr 1 14:34:51 MSD 2009

Hi all,

I have nginx proxying to a couple of thin servers.

For a request like /javascripts/foo.js a controller called 'javascripts' generates some dynamic js and caches it to $document_root/javascripts/foo.js.

The relevant part of the nginx config file:

root /apps/foo-app/current/public;
  location / {
    proxy_set_header  X-Real-IP  $remote_addr;

    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect false;
    proxy_max_temp_file_size 0;

    if (-f $request_filename) {

    if (!-f $request_filename) {
      proxy_pass http://thins;

    location ~* \.(js|css|jpg|jpeg|gif|png)$ {
      if (-f $request_filename) {
        expires      max;


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?


Posted at Nginx Forum:,700,700#msg-700

More information about the nginx mailing list