I have 2 scenarios:
/media/cache/test.jpg
orstylesheet/theme/xxxx.css
is generated by the application. It's not a static file present on the filesystem./assets/test.jpg
is a static file present on the host
I want both of them to be cached by the browser adding expires 6M
header.
So I did:
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_pass unix...;
internal;
}
location ~ \.php$ {
return 404;
}
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif)$ {
expires 6M;
access_log off;
# try accessing the file directly, and if not found
# it means the application has to generate it,
# so reroute to the @rewriteapp rule.
try_files $uri @rewriteapp;
}
Problem is nginx detects a loop:
*194369 rewrite or internal redirection cycle while redirect to named location "@rewriteapp", client: 127.0.0.1, server: , request: "GET /stylesheet/theme/3441-1484735061.css
What am I missing please ?
Ok, so replacing
try_files $uri @rewriteapp;
bytry_files $uri /index.php$is_args$args;
seems to fix the problem.