• minio+ nginx rewrite 实现saas租户的个性化管理


    这个是一个基于minio+nginx的rewrite 实现的一个功能(类似micro frontend 模式)

    参考架构

    • 一张架构图

    • 说明
      因为当前大家主流的还是基于前后端分离的模式开发软件,组件+api 实现功能,但是很多时候好多租户对于功能有个性化需求,但是
      系统在设计的时候因为时间问题+早期设计问题造成业务扩展能力有点差,还需要支持个性化需求开发,所以我们可以拆分标准版本
      以及自定型版本,同时基于minio 提供的s3 管理模式,对于不同的租户创建不同的bucket,标准的使用标准版,这样客户化开发就很简单
      了(特殊场景需要个性化),此方案的缺点也比较明确:空间的占用,但是还好因为前后端分离的模式。每个租户占用的静态资源也不是
      很大,核心问题是在系统更新的时候,我们可能需要引导客户自己升级或者基于强大的ci/cd 系统进行所有租户的系统升级(构建包的处理)
      个人感觉好处也是很明显的,如果我们的api 以及website 已经做了比较好的版本管理,用户切换版本也就是静态资源的替换(直接基于s3 bucket)。
      saas 应用的功能主要基于单页面的模式开发的应用,在s3 中的存储就是css,js 以及静态html 页面。这样管理起来也是比较灵活的

    环境准备

    • docker-compose 文件
     
    version: "3"
    services: 
      minio: 
        image: minio/minio
        command: server /data
        volumes: 
        - "./data:/data"
        ports: 
        - "9000:9000"
        environment:
          - "MINIO_ACCESS_KEY=minio"
          - "MINIO_SECRET_KEY=minio123"
      api:
        image: openresty/openresty:alpine
        volumes:
        - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
        - "./demoapps:/opt/demoapps"
        ports:
        - "80:80"
        - "8080:8080"
    • nginx 配置
    worker_processes  1;
    user root;  
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        gzip  on;
        rewrite_log on;
        real_ip_header     X-Forwarded-For;
        server {
           listen 80;
           charset utf-8;
           default_type text/html;
           location / {
                root /opt/demoapps/;
                index index.html index.htm index;
                # 不同规则的重写(比如固定的几个),注意last 与break 的区别,此处前缀使用了demo
                rewrite ^(.*?)(.html)?/(d+)$ /demo$3$1.html last;
                # rewrite ^(.*?)(.html)?/2$ /demo2$1 last;
           }
           error_page 404 /404.html;
           # 不存在默认界面
           location = /404.html {
                root /opt/demoapps/;
           }
           location =/favicon.ico {
                root /opt/demoapps/;
           }
          # 基于nginx proxy minio 数据
           location ~* ^/demo {
               internal;
               proxy_set_header Host $http_host;
               proxy_set_header X-Forwarded-For $remote_addr;
               client_body_buffer_size 10M;
               client_max_body_size 10G;
               proxy_buffers 1024 4k;
               default_type text/html;
               index index.html index.htm index;
               proxy_read_timeout 300;
               proxy_next_upstream error timeout http_404;
               proxy_pass http://minio:9000;
           }
        }
    }
     

    nginx 配说明:
    主要是参考上边的架构图,使用rewrite 基于正则解析请求,然后进行重写,同时对于用户的数据基于proxy 代理,为了安全使用了internal 模式

    • 启动服务
     
    docker-compose up -d
    • 创建租户的website 数据

    使用了前缀以及id 的格式,如下,具体html 代码参考github https://github.com/rongfengliang/openresty_rewrite_static/tree/minio
    注意需要配置bucket 的权限为* read only

    效果

    • 访问

    租户1首页应用:
    首页


    租户1另外一个应用:


    租户2的首页应用

    说明

    以上是一个minio+nginx rewrite 实现的一种多租户个性化开发的实践,希望对大家有用

    参考资料

    https://github.com/rongfengliang/openresty_rewrite_static/tree/minio

  • 相关阅读:
    c#调用DLL
    蚁群算法
    ManualResetEvent类的使用
    AsyncResult 类的使用
    同步调用与异步调用
    MFC套接字编程
    windows套接字编程
    socket的IO模型
    socket编程基础知识
    Hog行人检测
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13335382.html
Copyright © 2020-2023  润新知