轉載出處 https://blog.csdn.net/qq_39523874/article/details/109156215
1.后台部署
bin/package.bat 在項目的目錄下執行
然后會在項目下生成 target文件夾包含 war 或jar (多模塊生成在ruoyi-admin)
1、jar部署方式
使用命令行執行:java –jar ruoyi.jar 或者執行腳本:bin/run.bat
后台運行部署 nohup java -jar ruoyi.jar 2>1 &
改動過后,記得clear
2、war部署方式
pom.xml packaging修改為war 放入tomcat服務器webapps
打jar包
第一步。cd到ruoyi下面,打包jar包
mvn package
1
完成之后,發現多了個target文件夾,里面放的ruoyi.jar,即為所得
打包war包的方式(alternative)
1.需要打開rom.xml文件,修改配置。把
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>2.3.0</version>
<packaging>jar</packaging>
1
2
3
4
改成:
<packaging>war</packaging>
1
plus:打完jar包,再打war包。記得:
mvn clean //先清除
mvn package //在打包
1
2
Tomcat配置
修改server.xml,Host節點下添加
<Context docBase="" path="/" reloadable="true" source=""/>
1
dist目錄的文件夾下新建WEB-INF文件夾,並在里面添加web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<display-name>Router for Tomcat</display-name>
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
</web-app>
1
2
3
4
5
6
7
8
9
10
11
12
提示
SpringBoot去除內嵌tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 單應用排除內置tomcat -->
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2. 前端部署
以下為前端運行配置
# 進入項目目錄
cd ruoyi-ui
# 安裝依賴
npm install
# 強烈建議不要用直接使用 cnpm 安裝,會有各種詭異的 bug,可以通過重新指定 registry 來解決 npm 安裝速度慢的問題。
npm install --registry=https://registry.npm.taobao.org
# 本地開發 啟動項目
npm run dev
1
2
3
4
5
6
7
8
9
10
11
當項目開發完畢,只需要運行一行命令就可以打包你的應用
# 打包正式環境
npm run build:prod
# 打包預發布環境
npm run build:stage
1
2
3
4
5
構建打包成功之后,會在根目錄生成 dist 文件夾,里面就是構建打包好的文件,通常是 ***.js 、***.css、index.html 等靜態文件。
通常情況下 dist 文件夾的靜態文件發布到你的 nginx 或者靜態服務器即可,其中的 index.html 是后台服務的入口頁面。
outputDir 提示
如果需要自定義構建,比如指定 dist 目錄等,則需要通過 config (opens new window)的 outputDir 進行配置。
publicPath 提示
部署時改變頁面js 和 css 靜態引入路徑 ,只需修改 vue.config.js 文件資源路徑即可。
publicPath: './' //請根據自己路徑來配置更改
1
export default new Router({
mode: 'hash', // hash模式
})
1
2
3
環境變量
所有測試環境或者正式環境變量的配置都在 .env.development (opens new window)等 .env.xxxx文件中。
它們都會通過 webpack.DefinePlugin 插件注入到全局。
注意!!!
環境變量必須以VUE_APP_為開頭。如:VUE_APP_API、
VUE_APP_TITLE
你在代碼中可以通過如下方式獲取:
console.log(process.env.VUE_APP_xxxx)
1
Nginx配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /home/ruoyi/projects/ruoyi-ui;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
# 如果是測試環境則使用/stage-api/
# 后台服務代理
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
# 圖片路徑代理
location /profile/ {
# 方式一:指向地址
proxy_pass http://localhost:8088/profile/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
運行命令
/usr/local/nginx/sbin/nginx -s reload
1
常見問題
如果使用Mac 需要修改application.yml文件路徑profile
如果使用Linux 提示表不存在,設置大小寫敏感配置在/etc/my.cnf 添加lower_case_table_names=1,重啟MYSQL服務
如果提示當前權限不足,無法寫入文件請檢查profile是否可讀可寫,或者無法訪問此目錄
圖片上傳成功不能顯示
文件上傳成功后,請求訪問后台地址會根據profile進行匹配,需要自己配置nginx代理,參考如下。
location /profile/ {
# 方式一:指向地址
proxy_pass http://127.0.0.1:9999/profile/;
}
1
2
3
4
location /profile/
{
# 方式二:指向目錄,對應后台`application.yml`中的`profile`配置
alias /home/ruoyi/uploadPath/;
}
1
2
3
4
5
前端如何配置后端接口
對於特殊情況,需要直接調用后台接口或者指定域名可以修改.env.production文件VUE_APP_BASE_API屬性
# 后端接口地址
VUE_APP_BASE_API = '//localhost:8080'
1
2
圖片上傳成功不能顯示
參考文檔
https://doc.ruoyi.vip/ruoyi-vue/
1
文章知識點
————————————————
版權聲明:本文為CSDN博主「qq_372603103」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_39523874/article/details/109156215