location /media/ {
set $token $arg_token;
if ($arg_token = "") {
return 401;
}
auth_request /validate_token;
auth_request_set $auth_status $upstream_status;
# 根据令牌验证结果来控制文件访问
root D:/test;
}
location =/validate_token {
internal;
proxy_pass http://localhost:8000; # 向应用程序发送验证请求
proxy_set_header Authorization "Bearer $token";
proxy_set_header X-Original-URI $request_uri;
}