Api 如何基于代理响应有条件地为nginx中的静态文件提供服务?
我有一个文件夹Api 如何基于代理响应有条件地为nginx中的静态文件提供服务?,api,nginx,static-files,serving,limited-user,Api,Nginx,Static Files,Serving,Limited User,我有一个文件夹/static/uploads/limited,我需要配置nginx为特定用户提供一些文件。我还有一个API/API/auth/candownloadthis,它响应类似json的 { "result:"true" } 在为特定文件夹提供服务之前,如何让nginx检查API proxy_pass的响应 我需要的伪代码如下所示: location /static/uploads/limited{ IF /api/canIdownloadThis IS TRUE
/static/uploads/limited
,我需要配置nginx为特定用户提供一些文件。我还有一个API/API/auth/candownloadthis
,它响应类似json的
{
"result:"true"
}
在为特定文件夹提供服务之前,如何让nginx检查API proxy_pass的响应
我需要的伪代码如下所示:
location /static/uploads/limited{
IF /api/canIdownloadThis IS TRUE
THEN alias /my_secret_folder_path
}
因为我不想使用basic_auth。谢谢。多亏@stephenKing,我需要使用
--http\u auth\u request\u模块编译nginx
,然后创建一个响应403
或200
location ~* /(\w+)/static/limited/(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$
{
auth_request /IC/contents/can_i_access_limited;
alias /home/A/iB-system/C/$1/static/uploads/$2;
}
我还没用过,但朝这个方向发展的东西是。如果您的auth API返回正确的HTTP状态码,这可能会起作用。谢谢。你可以写下来,我会接受你的回答。