2015-11-13 42 views
3

我有一個文件夾/static/uploads/limited,我需要配置nginx將某些文件提供給特定用戶。我也有一個API /api/auth/canIDownloadThis其反應好像如何基於代理響應有條件地在nginx中提供靜態文件?

{ 
    "result:"true" 
} 

我怎樣才能讓nginx的檢查我的API proxy_pass的服務於特定的文件夾之前的響應JSON?

的僞代碼我需要的是這樣的:

location /static/uploads/limited{ 
    IF /api/canIdownloadThis IS TRUE 
    THEN alias /my_secret_folder_path 
} 

因爲我不想使用basic_auth。謝謝。

+2

還沒有使用它,但一些進入這個方向是[ngx_http_auth_request_module]( http://nginx.org/en/docs/http/ngx_http_auth_request_module.html)。如果您的auth API返回正確的HTTP狀態代碼,則可能會有效。 – StephenKing

+0

謝謝。你可以寫下這個,我會接受它作爲答案。 – Farsheed

回答

2

感謝@stephenKing,我需要編譯nginx的與--with-http_auth_request_module,然後創建一個API,響應403200

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; 
    }