Nginx ACCESS階段 統一的用戶權限驗證系統


L59

 

 

需要編譯到Nginx --with-http_auth_request_module

功能介紹:

主要當收到用戶請求的時候 通過反向代理方式生成子請求至上游服務器,如果上游服務器返回2xx 則驗證通過 可以繼續執行下去 如果返回錯誤碼是401或403則將相應返回用戶

auth_request 指令

syntax:auth_request uri | off;

default: off;

context: http,server,location

auth_request_set 指令

syntax :$variable value;

context:http,server,location

訪問 8090端口 將反向代理到 http://192.168.0.49/auth_upstream  如果返回200 則就繼續執行下去

server
  {
        listen 8090;#監聽端口
        #root html/;
        location / {
                auth_request /test_auth; #這里反向代理指向下面的路徑
        }
        location = /test_auth {
                proxy_pass http://192.168.0.49/auth_upstream;
                proxy_pass_request_body off;
                proxy_set_header Content-Length "";
                proxy_set_header X-Original-URI $request_uri;

        }
}

反向代理權限驗證服務器代碼示列

location /auth_upstream {
                return 403 "no ok";#返回403表示驗證不通過 200表示驗證通過
        }

satisfy 指令

syntax: all | any   注: all 所有驗證模塊通過才允許放行   any 只要一個模塊驗證通過就放行

default all;

context: http,server,location

注:satisfy 指令只要針對 三個模塊判斷  auth_request模塊  access模塊 auth_basic模塊   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM