我有两种情况:
/media/cache/test.jpg
或stylesheet/theme/xxxx.css
由应用程序生成。它不是文件系统上存在的静态文件。/assets/test.jpg
是主机上存在的静态文件
我希望它们两个都能被浏览器添加expires 6M
标头缓存。
所以我做了:
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;
}
问题是 nginx 检测到循环:
*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
请问我遗漏了什么?
答案1
好的,替换try_files $uri @rewriteapp;
似乎try_files $uri /index.php$is_args$args;
可以解决问题。