![](/img/trans.png)
[英]Django + NGINX Protecting Media Links using X-Accel-redirect not working
[英]Nginx x-accel redirect named location uri
我使用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 )
這也將轉發HTTP方法,直到nginx 1.10。 從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設置不同的位置,因此應設置具有位置的其他標頭,並在nginx config中執行以下操作:
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...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.