# Tweak proxy\_next\_upstream based on HTTP method

**URL:** <https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706>\
**Category:** NGINX\
**Created:** [July 5, 2013, 2:33pm UTC](https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706 "2013-07-05T14:33:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 5, 2013, 2:33pm UTC](https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706/1 "2013-07-05T14:33:03Z")

</div>

Hi all,

I was wondering if there is a way to have different proxy\_\* rules  
depending  
on the HTTP method? My use case is that I want to be a little more  
conservative about what requests I retry for POST requests, as they have  
an  
undesired impact if tried twice after a “false” timeout.

e.g., for GET, I may want to try another when I timeout to the back-end  
server after 5s, whereas for a POST request, I may want to simply fail  
the  
POST request after 15s.

I can work around this by doing specific location blocks for each URL,  
but  
having separate defaults based on HTTP method should be easier to  
maintain.

Thanks,  
Branden

---

<div class="post-metadata">

**Author:** ![Branden\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Branden\_V](https://www.ruby-forum.com/u/Branden_V)\
**Post date:** [July 5, 2013, 3:02pm UTC](https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706/2 "2013-07-05T15:02:51Z")

</div>

Hello!

On Fri, Jul 05, 2013 at 08:32:38AM -0400, Branden V. wrote:

> I can work around this by doing specific location blocks for each URL, but  
> having separate defaults based on HTTP method should be easier to maintain.

There is the limit\_except directive which might be helpful, see  
[Module ngx\_http\_core\_module](http://nginx.org/r/limit_except).

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Branden\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Branden\_V](https://www.ruby-forum.com/u/Branden_V)\
**Post date:** [July 5, 2013, 3:27pm UTC](https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706/3 "2013-07-05T15:27:59Z")

</div>

Thanks for the quick reply Maxim. That looks interesting, though in  
particular proxy\_next\_upstream and proxy\_read\_timeout don’t report to be  
valid in that context. I’ll give it a try, perhaps it’s just an error in  
the docs.

---

<div class="post-metadata">

**Author:** ![Branden\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@Branden\_V](https://www.ruby-forum.com/u/Branden_V)\
**Post date:** [July 5, 2013, 3:46pm UTC](https://www.ruby-forum.com/t/tweak-proxy-next-upstream-based-on-http-method/245706/4 "2013-07-05T15:46:41Z")

</div>

No it doesn’t look like limit\_except will allow me to change behaviour  
of  
proxy timeouts or next\_upstream based on the HTTP method. Are there any  
recommendations on how this could be done aside from my workaround?
