我有以下处理资产的位置:
location ~ \.(?:css|js|jpe?g|png) {
root /var/static;
}
因此,如果请求是
www.mysite.com/img/file.png
file.png将取自
/var/static/css/file.png
这是对的。但在某些情况下,我需要处理以下请求:
www.mysite.com/css/file1.png
从img目录中取出它
/var/static/img/file1.png
我应该如何更改位置?
答案 0 :(得分:1)
尝试这样的事情
# images that start with css
location ~ ^css(?:/[^/])*(?<filename>/[^/]*\.(?:jpe?g|png)) {
root /var/static;
try_files css/$filename img/$filename;
}
#normal images
location ~ (?<filename>[^/]+\.(?:jpe?g|png)) {
root /var/static;
try_files $filename $filename/;
}
#put separate rules for js and css