windows服務環境使用Nginx部署springboot+vue專案
部署步驟:先在服務器上搭建運行環境,Nginx,MySQL,JDK,Redis,
注意:要先將springboot的組態檔application.yml下的redis,資料源的地址埠密碼改成服務器環境下的,然后將springboot專案打成jar包,如果最終需要執行的jar包下有多個組態檔可以使用此命令進行指定組態檔執行jar包
nohup java -jar $APP_NAME --spring.profiles.active=$APP_ACTIVE
$APP_NAME:jar包名稱(模塊名)
$APP_ACTIVE:組態檔名
第一步:windows服務器環境搭建:
1、MySQL8.0(開發時使用的版本,避免語法問題)
2、Nginx1.10(無所謂)
3、JDK1.8
4、Redis

第二步:打包vue專案,進入vue專案目錄下,使用命令列執行 npm run build:prod,得到dist檔案

第三步:打包springboot專案,將springboot專案打包成為可執行jar包,
注意:作者在這里擺了個巨大的烏龍

如圖所見,該專案是一個多模塊的父子工程,每個模塊target檔案夾都有一個jar包,在這里xp-admin是最終打包成需要執行的jar包,但是在打包的時候需要注意,因為xp-platform是父級模塊(包含其它7個子模塊),我們執行的package命令是xp-platform模塊下的package命令,這樣打成 的jar包才能包含配置完全依賴關系的父模塊的pom檔案,建議打jar包順序clean–>install–>package,

第四步 :Nginx配置,以下圖片是解壓過后的目錄檔案,修改conf目錄下的nginx.conf檔案

配置nginx發布服務
server{
listen 9001;#埠號,訪問埠號
server_name localhost;#可配置訪問地址,域名(如果發布在內網就不需要配置)
index index.html;#首頁面
location / {
//vue專案打包后的dist檔案
root /Users/chenwy/Project/xp-platform/xp-ui/dist;#靜態檔案路徑
try_files $uri $uri/ /index.html last; #官網介紹設定這條可以解>決history路由的問題
}
#反向代理 /prod-api為vue定義的VUE_APP_BASE_API背景關系
location /prod-api {
rewrite ^/prod-api/(.*)$ /$1 break;#對指定的路徑進行轉發到后臺
proxy_pass http://127.0.0.1:8090;#后臺管理端系統spring boot
proxy_set_header X-Real-IP $remote_addr;#反向代理轉發真實IP
proxy_set_header X-Forwarded-For $remote_addr;
}
#解決路由不跳轉問題
location @router {
rewrite ^.*$ /index.html last;#其他頁面路徑不存在跳轉
}
#解決頁面訪問空白問題
location ^~/v-pages/{
rewrite ^/v-pages/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9002;#監聽9001埠,然后把v-pages/的請求 代理轉發到9002 埠,
}
}
server{
listen 9002;
root /Users/chenwy/pages;#頁面檔案路徑
location / {
root /Users/chenwy/pages;#頁面檔案路徑
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
第五步:如何配置Redis為windows服務(開機自啟動)
切換到redis所在目錄下使用該命令redis-server.exe --service-install redis.windows.conf,成功注冊則提示“Redis successfuly installed as a service”

第六步:如何將Nginx注冊為windows服務(開機自啟動)
新增檔案nginx-service.exe(復制nginx.exe重命名),nginx-service.exe.conf,nginx-service.xml

nginx-service.exe.conf下的代碼
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
nginx-service.xml下的代碼
<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description>
<logpath>D:\Nginx\nginx-1.18.0\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<executable>D:\Nginx\nginx-1.18.0\nginx.exe</executable>
<startarguments>-p D:\Nginx\nginx-1.18.0\nginx</startarguments>
<stopexecutable>D:\Nginx\nginx-1.18.0\nginx.exe</stopexecutable>
<stoparguments>-p D:\Nginx\nginx-1.18.0\nginx -s stop</stoparguments>
</service>
1、下載nssm

2、解壓后的目錄如下,我們選擇win64位的

3、在win64目錄下進入cmd,輸入命令nssm install
Application標簽說明:
Application Path: 選擇系統安裝的exe,
Startup directory: 選擇exe專案的根目錄,
Arguments: 輸入啟動引數

Just Do It:
“你忽略了時間的力量,一隊螞蟻每天搬運米粒大小的石塊,給它十億年,就能把泰山搬走,只要把時間拉得足夠長,生命比巖石和金屬都強壯得多,比颶風和火山更有力,”

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/299497.html
標籤:其他
上一篇:手寫的C++ WebSocket Server(windows)
下一篇:一.專案前端發布說明
