我有两种情况:
/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
请问我错过了什么?
好的,所以替换
try_files $uri @rewriteapp;
似乎try_files $uri /index.php$is_args$args;
可以解决问题。