一、Ruoyi-Vue前后端分離項(xiàng)目結(jié)構(gòu)
二、Redis部署
1、下載Windows版本Redis
2、解壓縮到安裝目錄
3、在安裝目錄欄輸入cmd,按回車鍵
4、將Redis綁定為 Windows 服務(wù),設(shè)置為后臺啟動
redis-server --service-install redis.windows.conf --loglevel verbose
或者
redis-server --service-install redis.windows-service.conf --loglevel verbose
5、常用命令
啟動服務(wù)
redis-server --service-start
停止服務(wù)
redis-server --service-stop
卸載命令
redis-server --service-uninstall
6、停止和啟動也可以通過頁面來操作
右鍵 此電腦 -->管理–>服務(wù) --> 找到"Redis"
三、后端部署
1、項(xiàng)目下\RuoYi-Vue\ruoyi-admin\src\main\resources\application.yml 下查看后端端口
2、打開項(xiàng)目文件夾下的bin目錄,先執(zhí)行clean.bat,再執(zhí)行打包命令package.bat
3、后端打包成功后,jar包存放于項(xiàng)目目錄\RuoYi-Vue\ruoyi-admin\target\ruoyi-admin.jar
4、查看Windows服務(wù)器上的jdk環(huán)境變量
右鍵 此電腦 -->屬性–>高級系統(tǒng)設(shè)置 --> 環(huán)境變量 --> 系統(tǒng)變量
5、在jdk環(huán)境變量配置路徑的bin目錄下找到javaw.exe
,復(fù)制一份修改成xxx.exe(名字任意取,原則和jar包的名稱保持一致)
例如 D:\Java\jdk1.8.0_131\bin 下面將
javaw.exe
改成test-ruoyi-admin.exe
6、編寫執(zhí)行啟動的bat腳本文件,首先需要將jar包放到自己的工作目錄下,同時(shí)在此目錄下新建一個(gè)啟動腳本:start-ruoyi-admin.bat
注意啟動腳本,jar包要放在同一個(gè)目錄
@echo off
start test-ruoyi-admin -jar D:\test\ruoyi-admin.jar >> D:\test\log &
exit
7、內(nèi)容說明
內(nèi)容 | 說明 |
---|---|
test-ruoyi-admin | 第5步在jdk的bin目錄下自定義的文件 |
D:\test\ruoyi-admin.jar | jar包存放的絕對路徑 |
D:\test\log & | 為log日志存儲路徑 |
8、文件結(jié)構(gòu)
9、啟動腳本,右鍵,以管理員身份運(yùn)行
10、打開任務(wù)管理器,查看自己的程序進(jìn)程號
四、前端部署
1、vue.config.js文件下修改前端端口
默認(rèn)是80端口,但不推薦使用80端口。因?yàn)?0端口在部署到服務(wù)器上和nginx可能存在占用等問題
target的url和端口要和服務(wù)器上能訪問到的后臺接口一致
2、打開項(xiàng)目文件夾下的D:\workspace\RuoYi-Vue\ruoyi-ui\bin
目錄,執(zhí)行打包命令build.bat
3、生成dist文件 ,前端打包成功
五、nginx部署
1、進(jìn)入nginx官網(wǎng),下載自己所需的版本
2、打開解壓后文件,修改配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
# listen下的端口就是代理前的接口,要與前面前端項(xiàng)目的vue.config.js中的端口一致
listen 8800;
# server_name是部署項(xiàng)目的服務(wù)器ip,即使是使用的本地也建議不要用localhost,避免修改hosts文件導(dǎo)致的問題
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# location /下面配置的就是代理前前端靜態(tài)資源的路徑等
location / {
# root 對應(yīng)的就是在服務(wù)器上前端資源的dist目錄的全路徑,即代表根路徑
root D:/workspace/RuoYi-Vue/ruoyi-ui/dist;
# 保持默認(rèn)不要更改,防止404和入口頁面
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
# location /prod-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就是設(shè)置的代理后的地址,即自己服務(wù)器后臺接口的url
proxy_pass http://localhost:8080/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
3、只要是通過http://localhost/8800/發(fā)送過來的請求全部會被代理到http://localhost:8080/。這樣就能實(shí)現(xiàn)前后端項(xiàng)目的請求代理
4、常用命令
常用命令 | 說明 |
---|---|
start nginx | 啟動命令 |
nginx.exe -s stop | 強(qiáng)制停止命令 |
nginx.exe -s reload | 重啟命令 |
六、部署完成
部署完成,瀏覽器輸入http://localhost/8800,登錄系統(tǒng)
常見問題:端口占用
①查找被占用的端口
# 查找使用的端口
netstat -ano
# 查找指定的端口
netstat -ano |findstr 1883
文章來源:http://www.zghlxwxcb.cn/news/detail-541187.html
②停止端口文章來源地址http://www.zghlxwxcb.cn/news/detail-541187.html
# 停用端口
taskkill -PID 8984 -F
# 查看占用此端口的進(jìn)程,在任務(wù)管理器中強(qiáng)制結(jié)束
tasklist|findstr 8984
到了這里,關(guān)于【后臺部署】Windows服務(wù)器部署RuoYi-Vue前后端分離項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!