Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward to named route or rewrite? #36

Open
frozenminds opened this issue Apr 7, 2015 · 1 comment
Open

Forward to named route or rewrite? #36

frozenminds opened this issue Apr 7, 2015 · 1 comment

Comments

@frozenminds
Copy link

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!

@agentzh
Copy link
Member

agentzh commented Apr 9, 2015

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants