Different locations based on $request_method
Aaron Starr
astarr at wiredquote.com
Sat Dec 4 00:42:28 MSK 2010
To follow up on my own question:
Maxim Dounin, in response to another question in the forum, recommended this
version to get a very similar effect and avoid the if:
location / {
# static handler returns 405 for POST and PUT requests to a static
file
error_page 405 = @sinatra;
try_files $uri $uri/index.html $uri.html @sinatra;
}
location @sinatra {
...
proxy_pass http://app_servers;
}
On Thu, Dec 2, 2010 at 12:55 PM, Aaron Starr <astarr at wiredquote.com> wrote:
>
> Hello, all,
>
> I would like to configure nginx to return a file if the request method is
> GET. But, if the request method is PUT or POST, I'd like for the back end to
> handle it. So, ideally, something like this:
>
> location / GET {
> try_files $uri $uri/index.html $uri.html @missing;
> }
>
> location / PUT {
> proxy_pass http://sinatra;
> ....
> }
>
> location @missing {
> return 404;
> }
>
> I understand that that particular syntax isn't possible. Is something like
> this the best way to do it?
>
> location / {
>
> if ($request_method = PUT) {
> proxy_pass http://sinatra;
> ....
> break;
> }
>
> try_files $uri $uri/index.html $uri.html @missing;
> }
>
> location @missing {
> return 404;
> }
>
> I'm aware that if==bad, but not sure if there's a better way to redirect
> traffic based on the request method?
>
> Thanks for any help,
>
> Aaron
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20101203/20c14655/attachment-0001.html>
More information about the nginx
mailing list