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
一键安装编译脚本
Link: Nginx 常见配置
2854





