当前位置: 代码网 > it编程>数据库>Mysql > Nginx转发鉴权全过程

Nginx转发鉴权全过程

2025年06月08日 Mysql 我要评论
nginx 配置 location /live { auth_request /auth; proxy_pass http://live_address;

nginx 配置

 location /live {
        auth_request    /auth;
        proxy_pass      http://live_address;
    }
    
  # authentication url
    location = /auth {
        proxy_pass      http://back_server/echo;
    }

需要nginx 安装auth_request 模块

后台编写接口

编写接口echo 判断用户是否登录,如果未登录

@restcontroller
public class echocontroller {

    @requestmapping("echo")
    public void echo() {
        authentication auth = securitycontextholder.getcontext().getauthentication();
        if (auth instanceof anonymousauthenticationtoken) {
            response.setstatus(httpservletresponse.sc_unauthorized);
        }
    }
}

nginx 安装auth_request 模块

–with-http_auth_request_module

一键安装编译脚本

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com