Skip to content

Instantly share code, notes, and snippets.

@thresheek
Created March 3, 2016 18:46
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save thresheek/2fa6479ffb7aca710493 to your computer and use it in GitHub Desktop.
Save thresheek/2fa6479ffb7aca710493 to your computer and use it in GitHub Desktop.
upstream backends {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
map $request_method $nonidempotent {
'POST' 1;
'PUT' 1;
'DELETE' 1;
default 0;
}
server {
listen 80;
location / {
if ($nonidempotent) {
rewrite ^ @nonidem last;
}
proxy_pass http://backends;
}
location = @nonidem {
internal;
proxy_next_upstream off;
proxy_pass http://backends$request_uri;
}
}
@JensRantil
Copy link

Hm, where is @nonidem defined?

@JensRantil
Copy link

Ah, I see. The rewrite defines it.

@gfrankliu
Copy link

What if one of the upstream servers is down? Since proxy_next_upstream is off, does that mean 50% of PUT/POST/DELETE calls will fail? Is there a way to still allow proxy_next_upstream during upstream connection failure (eg: connection timeout or connection refused)? Since it is not even connected and request is not sent to failed upstream, it should be safe to try next upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment