通过nginx做身份验证网关的方法

通过在nginx中,设置auth_request 参数。可以实现身份验证。

events{}
http{

server {
    listen 80;    #监听端口;
    server_name localhost; #服务器名称或域名;
    location / {
        auth_request /auth;     #要跳转的路由路径;
        proxy_pass http://localhost:52744/Auth;
    }
      #身份验证判断用户名和密码的方法的地址。此处例子登陆成功后跳转到/api/token/validate;
    location /Auth/Login {
        proxy_pass http://localhost:52744/Auth/Login;
        # Login service returns a redirect to the original URI
        # and sets the cookie for the ldap-auth daemon
        proxy_set_header X-Target $request_uri;
    }
     #身份验证成功后的地址,可以后台的api。只要能判断是否验证成功就行;
    location /api/token/validate {
        proxy_pass http://localhost:52744/api/token/validate;
        # Login service returns a redirect to the original URI
        # and sets the cookie for the ldap-auth daemon
        proxy_set_header X-Target $request_uri;
    }
      #执行身份验证的登陆页面地址,此处的页面会提交表单到/Auth/Login;
    location /auth {
        internal;
        proxy_pass   http://localhost:52744/Auth;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Target $request_uri;
    }

 

}

}

posted @   过错  阅读(868)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示