Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to easily clear the browser's cache when js/css files are updated.

Real file location:

  • /js/some-files.js
  • /css/some-files.css

File location set in the app to be called by browser:

  • /js/v1/some-files.js
  • /css/v1/some-files.css

I tried the following but going to /js/v1/some-files.js gives me 404s.

location ~ ^/(js|css)/v[0-9]+/(.*)$ {
    access_log off;
    expires 7d;
    add_header Cache-Control public;
    try_files $uri $uri/ $1/$2;

Can you spot what I'm doing wrong?

share|improve this question
It's probably the try_files directive that should probably read like... try_files $uri $uri/ /$1/$2; – Pothi Sep 14 '13 at 6:37
Well that was easy! It was that missing slash! – iDev247 Sep 14 '13 at 7:03
Glad to know it works. Posting it as answer, if you wish to upvote or select it as the best answer. ;-) – Pothi Sep 14 '13 at 7:12
up vote 1 down vote accepted

It was due to missing slash, as mentioned in the comments! Additionally, your location block can be simplified like the following...

location ~ /(js|css)/v[0-9]+/(.*) {
    access_log off;
    expires 7d;
    add_header Cache-Control public;
    try_files $uri $uri/ /$1/$2;
share|improve this answer
Thanks for the hint (the missing slash)! Looks like the ~ is however still required to trigger regular expression. – iDev247 Sep 14 '13 at 7:24
This issue also deviated to another issue… if you wish please check out my other quesiton – iDev247 Sep 14 '13 at 7:37
You're right. I've fixed it. Will look into the other issue now. – Pothi Sep 14 '13 at 8:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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