网站的底部设计,网络公司网站开发案例,有专门做最佳推荐的网站,南京网站开发南京乐识权威背景
目前我在集成登录认证功能#xff08;cas#xff09;#xff0c;使用的架构是nginxlua#xff0c;由于我们有多个系统#xff08;全是前端项目#xff09;#xff0c;每套系统都采用nginxlua的方式进行部署#xff08;即每个系统都是一个nginx#xff09;#…背景
目前我在集成登录认证功能cas使用的架构是nginxlua由于我们有多个系统全是前端项目每套系统都采用nginxlua的方式进行部署即每个系统都是一个nginxcas登录认证使用到了nginx缓存机制现在的问题在于这么一个场景
有两个项目A、B两个使用的是同一个域名C如下图 问题所在
用户的角度是AB是一套系统我登录了A到B系统我就不会在登录了…
开发角度因为A、B是两套nginx登录认证又使用到了nginx缓存这就造成一个问题访问A的使用用的是A系统的缓存访问B系统使用的是B系统的缓存即便在A系统登录了但是到B系统由于B系统没有缓存就会造成在登录一次
解决方案
对于上述的问题目前我想到了下面这几种方案各有优缺点选择自己最合适的就行
引入redis集中缓存使用共享磁盘使用一个nginx缓存路由的时候路由到共享磁盘的绝对路径上更改路径在使用缓存的地址上分别路由到各自的缓存上分别使用各自的缓存缺陷如果使用cookie的话会频繁刷新cookie,并且会给服务带来性能压力将项目部署同一个nginx上缺点部署发布的时候流程特别慢nginx要是炸的话项目全炸
方案一redis
统一使用redis缓存
将缓存使用一个集中式的就可以避免上述的问题而且还顺带解决了单点登录问题
优点
解决了缓存共享值问题解决单点登录问题
缺点
引入了redis系统复杂度变高维护成本也上升
方案二共享磁盘
这种方式是使用一个nginx的缓存在具体路由B项目的时候路由到共享磁盘的绝对路径上 相当于是B项目的部署只是为了将内容放到共享磁盘里面真正走的只有A系统通过location段路由到共享磁盘目录就行 A项目的nginx配置示例
server {listen 8080;server_name ~^test-(?subdomain.)\.aaaa\.com;# 禁止转发时携带端口port_in_redirect off;client_body_buffer_size 1024m;client_max_body_size 1024m;gzip on;gzip_min_length 1k;gzip_comp_level 2;gzip_types text/plain text/json application/javascript application/x-javascript text/css application/xml text/javascript font/ttf font/otf image/svgxml;gzip_vary on;set $hpath /usr/share/nginx/html/dist/$subdomain/;# 访问B项目的时候在这里写死共享磁盘路径location /info {set $hpath /home/dist/bdcInfo/;resolver 8.8.8.8; # access_log /home/cc.log main;# error_log /home/ww.log; access_by_lua_file /etc/nginx/cas.lua;default_type text/plain;alias $hpath;index index.html;try_files $uri $uri/ /index.html;}location / {resolver 8.8.8.8; # access_log /home/cc.log main;# error_log /home/ww.log; access_by_lua_file /etc/nginx/cas.lua;default_type text/plain;root $hpath;index index.html;try_files $uri $uri/ /index.html;}location /currentUser {default_type text/html;charset utf-8;# access_log /home/base-station-test11.log main;# error_log /home/qq.log;access_by_lua_file /etc/nginx/current_user.lua;}proxy_intercept_errors on;error_page 404 400 403 500 502 /404.html;location /404.html {root /home/resource;}
}优点
解决了上述问题
缺点
需要运维引入共享磁盘技术选型nfs ,fastdfsnas增加运维成本
方案三配置B的登录路由
需要前端配合请求权限的接口修改为B的前缀我这里使用到的登录接口为currentUser
nginx示例配置
server {listen 8080;server_name ~^test-(?subdomain.)\.aaaa\.com;# 禁止转发时携带端口port_in_redirect off;client_body_buffer_size 1024m;client_max_body_size 1024m;gzip on;gzip_min_length 1k;gzip_comp_level 2;gzip_types text/plain text/json application/javascript application/x-javascript text/css application/xml text/javascript font/ttf font/otf image/svgxml;gzip_vary on;set $hpath /usr/share/nginx/html/dist/$subdomain/;# 访问B项目的时候在这里写死共享磁盘路径location /info {set $hpath /home/dist/bdcInfo/;resolver 8.8.8.8; # access_log /home/cc.log main;# error_log /home/ww.log; access_by_lua_file /etc/nginx/cas.lua;default_type text/plain;alias $hpath;index index.html;try_files $uri $uri/ /index.html;}# 新增B请求登录的接口前缀location /info/currentUser {default_type text/html;charset utf-8;# access_log /home/base-station-test11.log main;# error_log /home/qq.log;access_by_lua_file /etc/nginx/lua/cas-auth/current_user.lua;}location / {resolver 8.8.8.8; # access_log /home/cc.log main;# error_log /home/ww.log; access_by_lua_file /etc/nginx/cas.lua;default_type text/plain;root $hpath;index index.html;try_files $uri $uri/ /index.html;}location /currentUser {default_type text/html;charset utf-8;# access_log /home/base-station-test11.log main;# error_log /home/qq.log;access_by_lua_file /etc/nginx/current_user.lua;}proxy_intercept_errors on;error_page 404 400 403 500 502 /404.html;location /404.html {root /home/resource;}
}这种方案成本比较低但是缺点也很明显
这种在请求A的时候会走登录请求B的时候也会走登录但是A,B域名一致就导致A,B的cookie来回重刷比较耗费性能
这里还有个疑问点是
为什么在登录了A之后在请求B的时候为什么不跳登录页而是直接走接口(这里没弄懂) 就是我第一次登录的时候访问AA会跳转到登录页然后输入用户名密码之后走了一系列的登录接口登录成功 这个时候在访问B B没有跳转到登录页跟A一样走的一模一样的登录接口然后登录成功 是因为同一域名的问题么没搞懂 方案四将AB部署在同一nginx上
这个就不用解释了但缺点很明显一旦nginx出现问题A,B项目都不能访问而且在部署的时候需要拉两套代码编译两套代码时间会很长
遗留问题
方案三最后的那几行确实没想通如果大家有什么想法的话欢迎沟通哈