gpt4 book ai didi

python - Nginx x-accel 重定向命名位置 uri

转载 作者:行者123 更新时间:2023-12-02 00:49:30 25 4
gpt4 key购买 nike

我使用 nginx x-accel-redirect 作为外部资源的身份验证前端。

在我的 python 代码中,我将执行以下操作:

/获取资源/

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-redirects 都作为 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;
}

最佳答案

由于这里没有人回答,所以我想把nginx论坛的答案贴出来补全。

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

你好,

这是您的工作。因为你不能使用 X-Accel-Redirect 来设置不同的位置,你应该用位置设置其他 header ,并在 nginx 配置中做像这样:

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

在上面的示例中,Python 代码应设置以下 header :

X-Accel-Redirect: @resources
X-Real-Location: /some/other/path...

关于python - Nginx x-accel 重定向命名位置 uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41105293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com