2

外部リソースの認証フロントエンドとして nginx x-accel-redirect を使用していました。

私のpythonコードでは、次のことを行います。

/getresource/

def view(self, req, resp): 
    name = get_name(req.user.id) # authenticates request.
    resp.set_header('X-Accel-Redirect', '/resource/%s/' %name ) 

これにより、nginx 1.10 までは HTTP メソッドも転送されます。nginx 1.10 以降、すべての x-accel-redirect は GET メソッドとして転送されます。

このスレッドから: https://forum.nginx.org/read.php?2,271372,271380#msg-271380

HTTP メソッドを転送する正しい方法は、名前付きの場所を使用することであることを理解しています。これを行う方法に関するドキュメントが見つかりません。私は次のことを試しました:

def view(self, req, resp): 
    name = get_name(req.user.id) 
    resp.set_header('X-Accel-Redirect', '@resource' ) 

ただし、これは「@resource /」にリダイレクトされます。

「@resource /name」にリダイレクトしたいと思います。

nginx フォーラムでもこの質問をしました: https://forum.nginx.org/read.php?2,271448

しかし、まだ応答がありません。

編集:

nginx の構成の投稿

location /getresource {
   proxy_pass http://127.0.0.1:8000;
}

location /resource {
    internal;
    proxy_pass http://127.0.0.1:8888;
}

location @resource {
    internal;
    proxy_pass http://127.0.0.1:8888;
}
4

1 に答える 1

6

誰もここに答えなかったので、nginxフォーラムからの回答を投稿して完成させたいと思います。

https://forum.nginx.org/read.php?2,271448,271549#msg-271549

やあ、

ここであなたがすること。X-Accel-Redirect を使用して別の場所を設定することはできないため、他のヘッダーに場所を設定し、nginx 構成で次のようにする必要があります。

location @resources {
    set $stored_real_location $upstream_http_x_real_location;
    proxy_pass http://resources-backend$stored_real_location;
}

上記の例では、Python コードは次のヘッダーを設定する必要があります。

X-Accel-Redirect: @resources
X-Real-Location: /some/other/path...
于 2016-12-22T11:34:58.167 に答える