基於子請求收到的HTTP響應碼做訪問控制
默認並未編譯進Nginx,通過--with-http-auth-request-module啟用
location / {
root html;
index index.html index.htm;
auth_request /auth;
}
location /auth {
#return 403 "error";
return 200 "success"
}
實際應用中,/auth中一般通過反向代理到鑒權服務器來返回狀態碼判斷是否通過驗證
location /private/ {
auth_request /auth;
}
location /auth {
proxy_pass http://127.0.0.1:8080/verify;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URL $request_uri;
}