JAR部署方案

正式环境部署

部署方案采用nginx+tomcat部署方案后端服务通过JAR方式运行前端项目build后的静态资源,部署到nginx中

一、后台项目jeecg-boot打jar包

目前 jeecg-boot-module-system 作为启动和打包项目。

1、修改数据库连接 application-prod.yml2、修改缓存redis配置 application-prod.yml3、修改上传附件配置 application-prod.yml输入图片说明4、切换配置为线上配置 application.yml 输入图片说明5、修改pom.xml加上打包插件(如果已经有了,就不需要加了)

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. </plugin>
  7. </plugins>
  8. </build>

然后 maven package 打jar包

二、后台项目jeecg-boot启动

通过命令启动项目

  1. Window启动命令:
  2. java -jar D:\jeecg-boot-module-system-2.0.0.jar
  3. Linux下后台进程启动命令:
  4. nohup java -jar jeecg-boot-module-system-2.0.0.jar >catalina.out 2>&1 &
  5. 关掉项目:
  6. ps -ef|grep java
  7. kill 进程号

三、前台项目build

1、修改后台接口服务地址 public/index.html

  1. window._CONFIG['domianURL'] = 'http://localhost:8080/jeecg-boot';
  2. window._CONFIG['imgDomainURL'] = 'http://localhost:8080/jeecg-boot/sys/common/view';
  3. window._CONFIG['pdfDomainURL'] = 'http://localhost:8080/jeecg-boot/sys/common/pdf/pdfPreviewIframe';

重要提示:

  1. 1. 后台服务接口地址,一定要配置外网的IP或者域名,配置内网域名后台访问不到的。
  2. 2. 后台启动默认名字jeecg-boot,不建议修改。如果需要修改,请自行替换此文中所有提到项目名jeecg-boot的地方;
  3. 同时修改前端代码 src/utils/request.js,里面的项目名字。
  1. const service = axios.create({
  2. baseURL: '/jeecg-boot', // api base_url
  3. timeout: 6000 // 请求超时时间
  4. })

2、build项目使用build命令打包项目输入图片说明build完成后台会生成一个dist的目录该目录下即为build后的文件。

3、nginx部署前端项目拷贝dist下的代码到nginx安装目录下html目录中,即可

四、nginx配置(conf/nginx.conf)

nginx监听80端口

  1. server {
  2. listen 80;
  3. server_name 你的域名;
  4. #后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问
  5. location ^~ /jeecg-boot {
  6. proxy_pass http://127.0.0.1:8080/jeecg-boot/;
  7. proxy_set_header Host 127.0.0.1;
  8. proxy_set_header X-Real-IP $remote_addr;
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  10. }
  11. #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题
  12. location / {
  13. root html;
  14. index index.html index.htm;
  15. if (!-e $request_filename) {
  16. rewrite ^(.*)$ /index.html?s=$1 last;
  17. break;
  18. }
  19. }
  20. }

五、nginx 开启压缩,提高首页访问效率

https://github.com/zhangdaiscott/jeecg-boot/issues/88

配置后启动nginx通过:http://你的域名 访问项目,出现如下页面,使用账户/密码:admin/123456 登录成功即可输入图片说明