Forward to named route or rewrite?
Hello,
How can I forward requests that did not match any cached entry to a named route?
I have something like:
location / {
try_files $uri $uri/ @backend;
}
location @backend {
rewrite / /index.php;
}
location ~ \.php$ {
# catch 404s
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Should I place srcache_fetch and srcache_store in location / or @backend? Are there any issues if the fallback is try_files or rewrite?
Thank you in advance!
@frozenminds You just need to be careful about running phases of each nginx directives used here. The basic running order in each location is
- if/rewrite (rewrite phase)
- srcache_fetch (end of access-phase)
- fastcgi_pass (content phase)
- srcache_store (during response sending to the downstream)
So if you use rewrite in a location, A, to initiate an "internal redirect" into another location, say, B. Then the srcache_fetch and srcache_store directives configured in location A will NEVER run.
The rule of thumb is to put srcache_fetch and srcache_store in the location containing your content handler modules' directives (like fastcgi_pass), no matter it is a named location or what.
BTW, please use the openresty-en mailing list for such general questions in the future. Please see http://openresty.org/#Community Thank you for your cooperation!