1

When I try to cache static files for the user, using

   location ~* \.(js|css|png|jpg|jpeg|gif|ico|bmp|ttf|tof|svg|swf)$ {
       expires max;
       access_log off;
       error_log off;
    }

The static files do not load (and give 403 Forbidden when accessed), so my site loads without any of those static files. When I comment out that part, everything works as should.

Can anyone explain why this is happening?

3
  • Your question is not clear. Maybe post a link to your full config. On a different point, these Nginx configs with long lists of static files found on the web have been outdated for almost two years now. Commented Mar 17, 2012 at 20:58
  • What's happening is that whenever I target any of those files through regex, it gives a 403 Foridden error. I replaced the query to just \.css$ and the images are loading fine now, just the css gives a 403 error. Commented Mar 17, 2012 at 21:25
  • After more testing, it doesn't even have to be regex - I made a full path the main wordpress css file, and that is still being 403ed. I chmod'd it to 0777 and made the group www-data which nginx is using into the owner Commented Mar 17, 2012 at 21:32

1 Answer 1

1

It's maybe because you don't specify any root directive in outer contexts (e.g. server block).

if you add a root directive to the server block or location block with path to your static folder it will be fixed:

server{
    .
    .
    .
    root /path/to/static/folder;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|bmp|ttf|tof|svg|swf)$ {

       # or add a root directive here
       root /path/to/static/folder;

       expires max;
       access_log off;
       error_log off;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.