request_filename vs try_files

Events happening in the community are now at Drupal community events on www.drupal.org.
wmostrey's picture

Cfr http://keen.posterous.com/your-nginx-configuration-is-probably-wrong

This post describes how in certain situations using if (-f $request_filename) {} and if (!-e $request_filename) {} can lead to unwanted behavior. A proposed solution is to use try_files $uri /index.php?$args; instead.

Is this something that applies to Drupal sites as well? Is anyone experiences these issues?

Comments

Yes

perusio's picture

that's the wrong way to do it. I didn't read the post you referenced. But it's wrong on a logical basis. Because you're trying to fit the Yoda style of reasoning that mod_rewrite promotes into the Nginx configuration. Nginx works in forward logical way, not reverse logic.

By using try_files you're saying: try to stat() this file if not found then try the next thing. Furthermore by using try_files you're abstracting the control flow, it is left at the syscall level instead of placing at the config level. Last but least, Nginx config language is mostly declarative. The only exceptions being the directives provided by the rewrite module, namely if, which are procedural.

Using try_files is relying on the declarative paradigm. Using procedural features like if or too much relying on regexes is bound to generate unwanted effects that mess up your setup. As rule of thumb don't use it if you can, if needed use it sparingly and try to use the "undocumented" best practices as wrapping regexes with nested locations.

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: