# Different locations based on $request\_method

**URL:** <https://www.ruby-forum.com/t/different-locations-based-on-request-method/200014>\
**Category:** NGINX\
**Created:** [December 2, 2010, 9:57pm UTC](https://www.ruby-forum.com/t/different-locations-based-on-request-method/200014 "2010-12-02T21:57:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 2, 2010, 9:57pm UTC](https://www.ruby-forum.com/t/different-locations-based-on-request-method/200014/1 "2010-12-02T21:57:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [December 3, 2010, 10:43pm UTC](https://www.ruby-forum.com/t/different-locations-based-on-request-method/200014/2 "2010-12-03T22:43:44Z")

</div>

To follow up on my own question:

Maxim D., 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;
}
```
