1、通过Nginx实现动静分离部署

基本原理:将乐创者静态资源部署到nginx服务下,后台应用部署到tomcat等应用服务器上。当浏览器访问时乐创者相关产品页面时,通过nginx进行代理,nginx服务根据配置规则将静态资源的请求直接返回而不再依赖tomcat等应用服务器,从而达到动静分离的目标。

动静分离部署带来什么好处?
1) Nginx本身就是一个高性能的静态web服务器;
2) 静态文件有一个特点就是基本上变化不大,所以动静分离以后我们可以对静态文件进行缓存、或者压缩提高系统性能。

1.1、配置说明

将乐创者静态资源文件夹及相关文件直接放在nginx安装目录/static{/lczServer}目录或其他固定目录下。

        # 报表/单元格表单/场景报表/透视分析/智能报告/跨设备表单/数智大屏/微应用/数据开发平台/数据模型/工作流设计/报表设计/模板管理中心等前端静态资源
        # 具体支持的前端资源范围与版本有关,可参考《动静分离配置》章节内容
        # 假设web应用名称为: lczServer,静态资源文件放在nginx安装目录/static/lczServer目录中
        # 注意:root可以使用相对路径(如果静态资源文件放在nginx安装目录/static目录下);alias只能使用绝对路径
        location ~ ^{/lczServer}/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/.*\.(html|htm)$ {
            root static/;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        location ~ ^{/lczServer}/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/ {
           # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }

        # 乐创者门户(v6.8.9版本新增)
        location ~ ^{/lczServer}/lczPortal/(assets|css|js|font)/ {
            # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
            root static/;
        }
        location {/lczServer}/lczPortal {
            alias nginx安装目录/static{/lczServer}/lczPortal;
            try_files $uri $uri/ /lczPortal/index.html;
            index index.html index.htm;

            # html页面禁止缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        # 小乐AI对话/管理段除html外的其他资源文件
        location ~ ^{/lczServer}/(lczChatAI|lczChatManage)/.*\.*$ {
           除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }
        # 小乐AI对话html页面
        location {/lczServer}/lczChatAI {
            alias nginx安装目录/static{/lczServer}/lczChatAI;
            try_files $uri $uri/ /lczServer/lczChatAI/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }
        # 小乐AI管理端html页面
        location {/lczServer}/lczChatManage {
            alias nginx安装目录/static{/lczServer}/lczChatManage;
            try_files $uri $uri/ {/lczServer}/lczChatManage/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

注意:
1)、{/lczServer} 在上面代表可选,例如lczServer.war包部署时是放在ROOT目录下,则可以省略;如果是改成其他名称的,修改为对应的名称即可。
2)、按需将lczServer.war根目录下的lczReport、lczCreater、lczCreater2、lczCloudForm、lczPortal、lczPortal2、lczCommon、lczMatrix、lczThird、lczWorkflow、lczMicroApp、lczDataStudio、lczDataModel、lczFlowDesigner、lczChatAI、lczChatManage、lczTemplateCenter、lczReportDesign等目录拷贝到nginx服务器对应目录下。

版本变更说明:
1、v6.8.0开始,新增lczCommon、lczMatrix;
2、v6.8.1开始,新增lczPortal、lczMicroApp;
3、v6.8.3开始,新增lczWorkflow;
4、v6.8.6版本开始,lczCreater变更为lczCreater、lczCreater2这2个目录;
5、v6.8.9版本开始,lczPortal变更为lczPortal、lczPortal2这2个目录;
6、v6.9.0版本开始,lczPortal变更为lczWorkflow、lczWorkflow2这2个目录;
7、v7.2.0开始,新增lczDataStudio;
8、v7.3.0开始,新增lczDataModel、lczFlowDesigner;
9、v8.0.0开始,新增lczChatAI、lczChatManage、lczTemplateCenter、lczReportDesign。

1.2、简单示例

示例1 、乐创者发布为lczServer目录

发布后,应用根目录路径为 lczServer,静态资源文件存放到nginx安装根目录/static/lczServer目录下。

       # 报表/单元格表单/场景报表/透视分析/智能报告/跨设备表单/数智大屏/微应用/数据开发平台/数据模型/工作流设计/报表设计/模板管理中心等前端静态资源
        # 具体支持的前端资源范围与版本有关,可参考《动静分离配置》章节内容
        # 假设web应用名称为: lczServer,静态资源文件放在nginx安装目录/static/lczServer目录中
        location ~ ^/lczServer/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/.*\.(html|htm)$ {
            root static/;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        location ~ ^/lczServer/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/ {
           # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }

        # 乐创者门户(v6.8.9版本新增)
        location ~ ^/lczServer/lczPortal/(assets|css|js|font)/ {
            # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
            root static/;
        }
        location /lczServer/lczPortal {
            proxy_set_header   Host             $host:$server_port;
            alias nginx安装目录/static/lczServer/lczPortal;
            try_files $uri $uri/ /lczPortal/index.html;
            index index.html index.htm;

            # html页面禁止缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        # 小乐AI对话/管理段除html外的其他资源文件
        location ~ ^/lczServer/(lczChatAI|lczChatManage)/.*\.*$ {
           除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }
        # 小乐AI对话html页面
        location /lczServer/lczChatAI {
            proxy_set_header   Host             $http_host;
            alias nginx安装目录/static/lczServer/lczChatAI;
            try_files $uri $uri/ /lczChatAI/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }
        # 小乐AI管理端html页面
        location /lczServer/lczChatManage {
            proxy_set_header   Host             $http_host;
            alias nginx安装目录/static/lczServer/lczChatManage;
            try_files $uri $uri/ /lczChatManage/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

同理,如果应用根目录路径为 report,则静态资源文件存放到nginx安装根目录/static/report目录下。

示例2、乐创者发布为ROOT目录

发布后,应用跟目录路径为 ROOT,静态资源文件存放到nginx安装根目录/static目录下。

       # 报表/单元格表单/场景报表/透视分析/智能报告/跨设备表单/数智大屏/微应用/数据开发平台/数据模型/工作流设计/报表设计/模板管理中心等前端静态资源
        # 具体支持的前端资源范围与版本有关,可参考《动静分离配置》章节内容
        # 假设web应用名称为: lczServer,静态资源文件放在nginx安装目录/static/lczServer目录中
        location ~ ^/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/.*\.(html|htm)$ {
            root static/;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        location ~ ^/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczReportDesign|lczTemplateCenter)/ {
           # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }

        # 乐创者门户(v6.8.9版本新增)
        location ~ ^/lczPortal/(assets|css|js|font)/ {
            # 除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
            root static/;
        }
        location /lczPortal {
            proxy_set_header   Host             $host:$server_port;
            alias nginx安装目录/static/lczPortal;
            try_files $uri $uri/ /lczPortal/index.html;
            index index.html index.htm;

            # html页面禁止缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

        # 小乐AI对话/管理段除html外的其他资源文件
        location ~ ^/(lczChatAI|lczChatManage)/.*\.*$ {
           除html外的其他(js/css/png/jpg等)静态资源文件,保持默认缓存策略
           root static/;
        }
        # 小乐AI对话html页面
        location /lczChatAI {
            proxy_set_header   Host             $http_host;
            alias nginx安装目录/static/lczChatAI;
            try_files $uri $uri/ /lczChatAI/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }
        # 小乐AI管理端html页面
        location /lczChatManage {
            proxy_set_header   Host             $http_host;
            alias nginx安装目录/static/lczChatManage;
            try_files $uri $uri/ /lczChatManage/index.html;
            index index.html index.htm;

            # 禁止html页面缓存
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            add_header Pragma "no-cache";
            add_header Expires "0";
        }

示例3、多个版本共用同一个Nginx

如同时部署了v6.8.5和v6.9.0个服务,改如何配置?
静态文件存放:
v6.8.5的放在 nginx安装根目录/static/v685/lczServer目录下;
v6.9.0的放在 nginx安装根目录/static/v690/lczServer目录下;
在对应的server下配置:

http
{
    server { #v6.8.5的服务
        # 报表/单元格表单/场景报表/透视分析/智能报告/跨设备表单/数智大屏/门户/微应用等前端静态资源
        location ~ ^/lczServer/(lczCommon|lczReport|lczCreater|lczCloudForm|lczPortal|lczMatrix|lczThird|lczWorkflow|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczChatAI|lczChatManage|lczReportDesign|lczTemplateCenter)/ {
                root static/v685/;
        }
        ...
    }

    server { #v6.9.0的服务
        # 报表/单元格表单/场景报表/透视分析/智能报告/跨设备表单/数智大屏/门户/微应用等前端静态资源
        location ~ ^/lczServer/(lczCommon|lczReport|lczCreater|lczCreater2|lczCloudForm|lczPortal2|lczMatrix|lczThird|lczWorkflow|lczWorkflow2|lczMicroApp|lczDataStudio|lczDataModel|lczFlowDesigner|lczChatAI|lczChatManage|lczReportDesign|lczTemplateCenter)/ {
                root static/v690/;
        }

        # 乐创者门户
        location /lczPortal {
          alias /usr/local/nginx/static/lczPortal;
          try_files $uri $uri/ /lczPortal/index.html;
          index index.html index.htm;
        }
        ...
    }
}

2 其他方式

暂无

作者:柳杨  创建时间:2023-06-08 15:59
最后编辑:柳杨  更新时间:2025-09-03 16:32