1. 程式人生 > 其它 >若依專案linux部署

若依專案linux部署

轉載出處  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