error_page and named locations

Igor Sysoev is at rambler-co.ru
Thu Dec 11 22:55:36 MSK 2008


On Thu, Dec 11, 2008 at 10:51:59AM -0800, mike wrote:

>  Thu, Dec 11, 2008 at 4:31 AM, Igor Sysoev <is at rambler-co.ru> wrote:
> 
> >      location / {
> >          file_match  $uri  @drupal;
> >          # the same as
> >          #    error_page  404 = @drupal; log_not_found off;
> >      }
> 
> This is a very common example - almost anything with "nice names" will
> pass the non-existent file requests to a single file handler. That's
> how we're designing our own application too (and how I design mine
> nowadays)
> 
> Is there a reason that a new parameter would need to be invented? Why
> is error_page not capable of this? (Note that I was using error_page
> in my 0.7.21 or so and the POST data was not coming through to my
> PHP/fastcgi scripts, which I thought was fixed a long while back) so
> I've been using if (-f $request_filename) for the time being (I don't
> want to test for dirs, only exact filenames, otherwise index files get
> factored in and I don't want those to be used actually, and I can't
> rename them right now)

I will look your POST/body issue.

> If this new parameter is affecting only fastcgi-based requests I would
> request it be prefixed with fastcgi_ at least for consistency (maybe
> fastcgi_fallback_pass or something?). If it is general purpose,
> file_try_match maybe. This is hard :)

No, the new directive is general purpose.

The most demonstrably usage is mongrel configuration, where you need
to test several static files existence:

      location / {
          use_file  $uri  $uri/index.html  $uri.html  @mongrel;
      }

      location @mongrel {
          ...
      }

Second usage is testing a script existence before passing it to backend:

      location ~ \.php$ {
          use_file  $uri  @drupal;

          fastcgi_pass   ...
          fastcgi_param  SCRIPT_FILENAME /path/to$script_filename;
      }

And finally, it can be used as simple replacement of

      location / {
          error_page  404 = @drupal; log_not_found off;
      }

as

      location / {
          use_file  $uri  @drupal;
      }

although I have no plan to drop "error_page" support.
The last "use_file" usage is just syntax sugar.

As to names, now I have three variants: use_file, test_file, try_file.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list