通过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;
}
}
}
作者:过错
出处:http://www.cnblogs.com/wang2650/
关于作者:net开发做的久而已。十余年时光虚度!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com
联系我,非常感谢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)