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
一键安装编译脚本
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论