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模块   

原文地址:https://www.cnblogs.com/jackey2015/p/10374227.html