nginx用户验证

有时候须要nginx在访问资源以前通过用户验证。html

nginx提供了一种基于文件的访问,还有一种是基于服务端的。配置以下。nginx

 

       location / {
        auth_request /auth;
        root C:/Users/Admin/Documents/NetBeansProjects/SpringBootSample/src/main/resources/public/;
        index index.html;
        try_files $uri $uri/ =404;
       }
       htm

       location = /auth {
        internal;
        proxy_pass http://localhost:8084/auth/login;
    
        }资源

 

说明,在访问根部/将会先经过/auth配置的http://localhost:8084/auth/login服务端,若是改服务回复200,那么就觉得用户验证经过,若是回复401那么就会拒绝访问,nginx将会返回错误给访问者。io

相关文章
相关标签/搜索