I am trying to get cache-comtrol to work.
In nginx I have the following:
location /static/ {
alias /home/ubuntu/workspace/mysite;
expires max;
add_header Cache-Control public;
}
in mysite dir I have static. In static I have the dirs for js, css, and images.
In the web browser I get 404 error. Images cant be found. If I remove location /static/ this site works but I have no cache-control.
How do I resolve?
If you use url like:
http://your.page.com/static/image.gifthen with your rules you get such uri (includingaliasdirective):So conclusion is that remove last
/fromlocationdirective (it should be/static) or add at the end toaliasdirective/(so it will be asalias /home/ubuntu/workspace/mysite/;)Other solution could be like:
Then you don’t have to add
staticagain inaliasdirective. You just use it as location param ($1 = static/.*).Why that way?
aliasdirective (alias doc) work as follow: it trims from requested url part matched inlocationdirective end then, with what will stay, append to it own rule path. In your example from url/static/image.gif/it will trim/static/and to youraliaspath append onlyimage.gifso it will look like I wrote: /home/ubuntu/workspace/mysiteimage.gif/`.