Nginx转发鉴权全过程
作者:Boom_Man
这篇文章主要介绍了Nginx转发鉴权全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
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
一键安装编译脚本
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。