JAR部署方案
正式环境部署
部署方案采用nginx+tomcat部署方案后端服务通过JAR方式运行前端项目build后的静态资源,部署到nginx中
一、后台项目jeecg-boot打jar包
目前 jeecg-boot-module-system 作为启动和打包项目。
1、修改数据库连接 application-prod.yml2、修改缓存redis配置 application-prod.yml3、修改上传附件配置 application-prod.yml4、切换配置为线上配置 application.yml 5、修改pom.xml加上打包插件(如果已经有了,就不需要加了)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
然后 maven package 打jar包
二、后台项目jeecg-boot启动
通过命令启动项目
Window启动命令:
java -jar D:\jeecg-boot-module-system-2.0.0.jar
Linux下后台进程启动命令:
nohup java -jar jeecg-boot-module-system-2.0.0.jar >catalina.out 2>&1 &
关掉项目:
ps -ef|grep java
kill 进程号
三、前台项目build
1、修改后台接口服务地址 public/index.html
window._CONFIG['domianURL'] = 'http://localhost:8080/jeecg-boot';
window._CONFIG['imgDomainURL'] = 'http://localhost:8080/jeecg-boot/sys/common/view';
window._CONFIG['pdfDomainURL'] = 'http://localhost:8080/jeecg-boot/sys/common/pdf/pdfPreviewIframe';
重要提示:
1. 后台服务接口地址,一定要配置外网的IP或者域名,配置内网域名后台访问不到的。
2. 后台启动默认名字jeecg-boot,不建议修改。如果需要修改,请自行替换此文中所有提到项目名jeecg-boot的地方;
同时修改前端代码 src/utils/request.js,里面的项目名字。
const service = axios.create({
baseURL: '/jeecg-boot', // api base_url
timeout: 6000 // 请求超时时间
})
2、build项目使用build命令打包项目build完成后台会生成一个dist的目录该目录下即为build后的文件。
3、nginx部署前端项目拷贝dist下的代码到nginx安装目录下html目录中,即可
四、nginx配置(conf/nginx.conf)
nginx监听80端口
server {
listen 80;
server_name 你的域名;
#后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问
location ^~ /jeecg-boot {
proxy_pass http://127.0.0.1:8080/jeecg-boot/;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题
location / {
root html;
index index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html?s=$1 last;
break;
}
}
}
五、nginx 开启压缩,提高首页访问效率
https://github.com/zhangdaiscott/jeecg-boot/issues/88
配置后启动nginx通过:http://你的域名 访问项目,出现如下页面,使用账户/密码:admin/123456 登录成功即可
当前内容版权归 Jeecg-Boot 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Jeecg-Boot .