0

I'm trying to make nginx send expiration headers, I tried in two different ways:

location ~* ^.+\.(ico|css|js|gif|jpe?g|png)\?[0-9]+$ {
  expires max;
}

and

location / {
  if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)\?[0-9]+$") {
    expires max;
    break;
  }
  #....
}

none of which worked. No expiration headers are sent whatsoever. Any ideas how to debug this issue?

2

Location should on path only, without query string, so this shouldn't work.

Try the following :

location ~* \.(ico|css|js|gif|jpe?g|png)$ {
    expires max;
}

or, at least, the following should work too :

location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
    expires max;
}
2

Test to make sure the locations block is being called by placing an additional directive in there..something like:

location ~* \.(ico|css|js|gif|jpe?g|png)$ {
    expires max;
    auth_basic "Restricted, please login";
    auth_basic_user_file htpasswd.users;
}

If you're not presented with a auth prompt when requesting matching files then you can be certain that the block is not being called due to an earlier break or what have you.

0

These lines actually worked, I was just testing them wrong. These lines correctly try to cache only timestamped resources (those with ?id at the end) and I was looking at non-timestamped ones.

0

Are using nginx as a caching proxy? If so be aware that upstream caching instructions are respected, but you can still instruct nginx not to using proxy_ignore_headers

proxy_ignore_headers X-Accel-Expires Expires Cache-Control;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.