Wanted: suggestions on how to invert proxy_pass return codes
Ruslan Ermilov
ru at nginx.com
Wed Mar 6 10:18:17 UTC 2013
On Tue, Mar 05, 2013 at 12:17:03AM +0000, Jonathan Matthews wrote:
> A slight thinko crept in to my original mail; there's a small
> difference (which does remove a minor complexity) as I've marked below
> ...
>
> On 4 March 2013 23:58, Jonathan Matthews <contact at jpluscplusm.com> wrote:
> [snip]
> > --------------------------------------------------------------------------
> > location /healthcheck/ {
> > if (!-f /tmp/flag) {
> > return 503;
> > }
>
> SHOULD BE:
>
> "
> if (-f /tmp/flag) {
> return 200;
> }
> "
>
> [snip]
> > --------------------------------------------------------------------------
> >
> > Before making the proxy_pass call, check a marker on disk and serve a
> > (real, not translated to =200) 503 if it exists.
>
> SHOULD BE: "... serve a 200 if it exists."
>
> I don't think this changes the meat of the problem - it just removes
> one minor niggle.
>
> Any thoughts?
Well, if you can add headers on a backend ...
: http {
: map $connection $fail {
: ~[02468]$ 1;
: }
:
: server {
: server_name backend;
: listen 8001;
: add_header X-Accel-Redirect /backend_up;
:
: if ($fail) { return 503 "real 503\n"; }
: return 200 "real 200\n";
: }
:
: server {
: listen 8000;
:
: location = /test {
: proxy_pass http://127.0.0.1:8001;
: proxy_intercept_errors on;
: error_page 503 = @backend_down;
: }
:
: location @backend_down {
: return 200 "wrapped 200\n";
: }
:
: location = /backend_up {
: internal;
: return 503 "wrapped 503\n";
: }
: }
: }
$ repeat 10 curl http://127.0.0.1:8000/test
wrapped 503
wrapped 200
wrapped 503
wrapped 200
wrapped 503
wrapped 200
wrapped 503
wrapped 200
wrapped 503
wrapped 200
(See http://nginx.org/r/proxy_ignore_headers for the meaning of
X-Accel-Redirect.)
More information about the nginx
mailing list