正式环境部署 ##正式环境部署 > 部署方案采用nginx+tomcat部署方案 > 后端服务发布部署到tomcat中 > 前端项目由于build后都是静态问题,部署到nginx中 ###一、后台项目jeecg-boot打war包 ####(1)后台项目jeecg-boot打war包之前要进行如下改动 1、pom.xml文件中项目打包格式设置为war <packaging>war</packaging> 具体配置如下: ``` <modelVersion>4.0.0</modelVersion> <groupId>org.jeecgframework.boot</groupId> <artifactId>jeecg-boot</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>war</packaging> ``` 2、增加项目web容器部署的支持: 修改类/src/main/java/org/jeecg/JeecgApplication.java 代码如下: ``` package org.jeecg; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 public class JeecgApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(JeecgApplication.class); } public static void main(String[] args) { System.setProperty("spring.devtools.restart.enabled", "true"); SpringApplication.run(JeecgApplication.class, args); } } ``` 3、修改线上数据库连接,redis地址 application.yml 4、修改上传附件配置 application.yml ``` #文件上传根目录 设置 uploadpath: D://upFiles ``` 然后maven install 或者 maven package 打war包 ###二、后台项目jeecg-boot部署tomcat 1、设置tomcat端口号 8080,设置tomcat编码 URIEncoding="UTF-8" 2、部署项目到tomcat安装目录webapps/jeecg-boot工程目录下 部署完后通过http://localhost:8080/jeecg-boot 可以访问到该项目 后台项目部署成功!! ###三、前台项目build 1、修改src/utils/request.js 中baseURL配置为 baseURL: '/jeecg-boot/' 具体代码如下: ``` // 创建 axios 实例 const service = axios.create({ baseURL: '/jeecg-boot/', // api base_url timeout: 6000 // 请求超时时间 }) ``` 2、修改src/api/api.js ``` //图片预览请求地址 const imgView = "http://{域名}/jeecg-boot/sys/common/view/"; const doMian = "/jeecg-boot/"; ``` 3、build项目 使用build命令打包项目  build完成后台会生成一个dist的目录该目录下即为build后的文件。 4、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; } } } ``` 配置后启动tomcat,启动nginx 通过http://你的域名/ 访问项目,出现如下页面,使用账户/密码:admin/admin 登录成功即可 