srcache-nginx-module icon indicating copy to clipboard operation
srcache-nginx-module copied to clipboard

Forward to named route or rewrite?

Open frozenminds opened this issue 10 years ago • 1 comments

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 avatar Apr 07 '15 13:04 frozenminds

@frozenminds You just need to be careful about running phases of each nginx directives used here. The basic running order in each location is

  1. if/rewrite (rewrite phase)
  2. srcache_fetch (end of access-phase)
  3. fastcgi_pass (content phase)
  4. 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!

agentzh avatar Apr 09 '15 20:04 agentzh