2017-11-02 43 views
0

nginxのauth_requestを使用して、わずか4リターンコードが受け入れられる:2xx401403500を。これらを処理するには、error_pageを設定する必要があります。これはauth_requestでは問題ありませんが、これらのコードを返すすべてのダウンストリームアプリは、同じerror_pageの処理を使用して終了します。nginxのauth_requestエラーが

location /test { 
    auth_request /foo; 
    error_page 500 /its-broke.html; 
    proxy_pass http://bar; 
} 
auth_request

/fooに戻る500場合、その-broke.htmlが示されています。これは私が望むふるまいです。ただし、bar500を返す場合は、its-broke.htmlも表示されます。私はこれを望んでいない。代わりに、私はbar500エラー応答をブラウザに送信する必要があります。

auth_requestはどの5xxをキャッチし、500としてそれを扱うので、私はちょうどfooリターン520を持つことができないだろう。それは、次のエラーが発生し、500はとにかく返されます。

auth request unexpected status: 520 while sending to client 

この周りを取得するための任意のアイデアを?プロキシのパスの前にerror_pageの設定を解除する方法が見つかりません。

答えて

0

APIテストから

events { 
    worker_connections 1024; 
} 
http { 

    server { 

     listen 80; 

     location @autherror { 

      return 500 "Auth returned 500"; 
     } 

     location @proxy_api { 

      proxy_pass http://127.0.0.1:8081; 
     } 

     location/{ 

      location /test { 

       auth_request /auth; 
       error_page 500 = @autherror; 
       try_files dummy_non_existing_url = @proxy_api; 
      } 

     } 
     location /auth { 

      return 200 "auth passed"; 
     } 

    } 

    server { 

     listen 8081; 
     location/{ 
      return 200 "You came to $uri"; 
     } 
     location /test2 { 
      return 500 "Error from API"; 
     } 
    } 
} 

結果は私が認証500エラーをシミュレートするreturn 500 "auth failed";return 200 "auth passed";を変更した場合さて、私は

を取得

$ curl localhost/test 
You came to /test 

$ curl localhost/test2 
Error from API 

ですが、あなたは、いくつかの努力でそれを行うことができます

$ curl localhost/test 
Auth returned 500 
関連する問題