try_files, POST, and redirecting requests to Passenger

António P. P. Almeida appa at perusio.net
Thu Jan 10 13:04:17 UTC 2013


On 9 Jan 2013 20h39 CET, lists at ruby-forum.com wrote:


> Sorry if I mispoke then, what I want is the exact opposte because
> POST should never hit a cache file.
>
> We ended up going a slightly different route in that we hack the
> cache file location according to the request type (we have
> $cache_host because there's some other processing we do, not
> relevant here):
>
> # Set cache_path to a non-existant directory so try_files fails if
> # we
> cannot
> # serve the request from the cache.
> set $cache_path "no-cache";
> set $cache_host $host;
>
> if ($request_method ~* ^(GET|HEAD)$) {
> set $cache_path "cache";
> }
>
> try_files
> /$cache_path/$cache_host/$uri
> /$cache_path/$cache_host/$uri.html
> /$cache_path/$cache_host/$uri/index.html
> /maintenance.html
> @passenger;
>
> This way there's no possible way a valid file is found when
> POST-ing.  This was the simplest solution we could come up with at
> this time.
>
> Thanks for everyone's help.

It's even simpler then. No need for map.

location / {
    error_page 418 = @post;

    if ($request_method = POST) {
        return 418;
    }

    try_files /cache/$domain/$uri /cache/$domain/$uri.html
    /cache/$domain/$uri/index.html /maintenance.html @passenger;
}

location @post {
   try_files /maintenance.html @passenger;
}

location @passenger {
   passenger_enabled on;
}

--- appa



More information about the nginx mailing list