[Win服务器] 【后台部署】Windows服务器部署RuoYi-Vue前后端分离项目

209 0
Honkers 2025-5-10 12:46:22 来自手机 | 显示全部楼层 |阅读模式
一、Ruoyi-Vue前后端分离项目结构

二、Redis部署

1、下载Windows版本Redis

2、解压缩到安装目录

3、在安装目录栏输入cmd,按回车键

4、将Redis绑定为 Windows 服务,设置为后台启动

  1. redis-server --service-install redis.windows.conf --loglevel verbose
复制代码

或者

  1. redis-server --service-install redis.windows-service.conf --loglevel verbose
复制代码

5、常用命令

启动服务

  1. redis-server --service-start
复制代码

停止服务

  1. redis-server --service-stop
复制代码

卸载命令

  1. redis-server --service-uninstall
复制代码

6、停止和启动也可以通过页面来操作

右键 此电脑 -->管理–>服务 --> 找到"Redis"

三、后端部署

1、项目下\RuoYi-Vue\ruoyi-admin\src\main\resources\application.yml 下查看后端端口

2、打开项目文件夹下的bin目录,先执行clean.bat,再执行打包命令package.bat

3、后端打包成功后,jar包存放于项目目录\RuoYi-Vue\ruoyi-admin\target\ruoyi-admin.jar

4、查看Windows服务器上的jdk环境变量

右键 此电脑 -->属性–>高级系统设置 --> 环境变量 --> 系统变量

5、在jdk环境变量配置路径的bin目录下找到javaw.exe,复制一份修改成xxx.exe(名字任意取,原则和jar包的名称保持一致)

例如 D:\Java\jdk1.8.0_131\bin 下面将javaw.exe改成test-ruoyi-admin.exe

6、编写执行启动的bat脚本文件,首先需要将jar包放到自己的工作目录下,同时在此目录下新建一个启动脚本:start-ruoyi-admin.bat

注意启动脚本,jar包要放在同一个目录

  1. @echo off
  2. start test-ruoyi-admin -jar D:\test\ruoyi-admin.jar >> D:\test\log &
  3. exit
复制代码

7、内容说明

内容说明
test-ruoyi-admin第5步在jdk的bin目录下自定义的文件
D:\test\ruoyi-admin.jarjar包存放的绝对路径
D:\test\log &为log日志存储路径

8、文件结构

9、启动脚本,右键,以管理员身份运行

10、打开任务管理器,查看自己的程序进程号

四、前端部署

1、vue.config.js文件下修改前端端口

默认是80端口,但不推荐使用80端口。因为80端口在部署到服务器上和nginx可能存在占用等问题

target的url和端口要和服务器上能访问到的后台接口一致

2、打开项目文件夹下的D:\workspace\RuoYi-Vue\ruoyi-ui\bin目录,执行打包命令build.bat

3、生成dist文件 ,前端打包成功

五、nginx部署

1、进入nginx官网,下载自己所需的版本

2、打开解压后文件,修改配置文件


  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. # listen下的端口就是代理前的接口,要与前面前端项目的vue.config.js中的端口一致
  24. listen 8800;
  25. # server_name是部署项目的服务器ip,即使是使用的本地也建议不要用localhost,避免修改hosts文件导致的问题
  26. server_name localhost;
  27. #charset koi8-r;
  28. #access_log logs/host.access.log main;
  29. # location /下面配置的就是代理前前端静态资源的路径等
  30. location / {
  31. # root 对应的就是在服务器上前端资源的dist目录的全路径,即代表根路径
  32. root D:/workspace/RuoYi-Vue/ruoyi-ui/dist;
  33. # 保持默认不要更改,防止404和入口页面
  34. try_files $uri $uri/ /index.html;
  35. index index.html index.htm;
  36. }
  37. # location /prod-api/ 是配置的代理后的地址
  38. location /prod-api/{
  39. proxy_set_header Host $http_host;
  40. proxy_set_header X-Real-IP $remote_addr;
  41. proxy_set_header REMOTE-HOST $remote_addr;
  42. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  43. # proxy_pass就是设置的代理后的地址,即自己服务器后台接口的url
  44. proxy_pass http://localhost:8080/;
  45. }
  46. #error_page 404 /404.html;
  47. # redirect server error pages to the static page /50x.html
  48. #
  49. error_page 500 502 503 504 /50x.html;
  50. location = /50x.html {
  51. root html;
  52. }
  53. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  54. #
  55. #location ~ \.php$ {
  56. # proxy_pass http://127.0.0.1;
  57. #}
  58. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  59. #
  60. #location ~ \.php$ {
  61. # root html;
  62. # fastcgi_pass 127.0.0.1:9000;
  63. # fastcgi_index index.php;
  64. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  65. # include fastcgi_params;
  66. #}
  67. # deny access to .htaccess files, if Apache's document root
  68. # concurs with nginx's one
  69. #
  70. #location ~ /\.ht {
  71. # deny all;
  72. #}
  73. }
  74. # another virtual host using mix of IP-, name-, and port-based configuration
  75. #
  76. #server {
  77. # listen 8000;
  78. # listen somename:8080;
  79. # server_name somename alias another.alias;
  80. # location / {
  81. # root html;
  82. # index index.html index.htm;
  83. # }
  84. #}
  85. # HTTPS server
  86. #
  87. #server {
  88. # listen 443 ssl;
  89. # server_name localhost;
  90. # ssl_certificate cert.pem;
  91. # ssl_certificate_key cert.key;
  92. # ssl_session_cache shared:SSL:1m;
  93. # ssl_session_timeout 5m;
  94. # ssl_ciphers HIGH:!aNULL:!MD5;
  95. # ssl_prefer_server_ciphers on;
  96. # location / {
  97. # root html;
  98. # index index.html index.htm;
  99. # }
  100. #}
  101. }
复制代码

3、只要是通过http://localhost/8800/发送过来的请求全部会被代理到http://localhost:8080/。这样就能实现前后端项目的请求代理

4、常用命令

常用命令说明
start nginx启动命令
nginx.exe -s stop强制停止命令
nginx.exe -s reload重启命令

六、部署完成

部署完成,浏览器输入http://localhost/8800,登录系统

常见问题:端口占用
①查找被占用的端口

  1. # 查找使用的端口
  2. netstat -ano
  3. # 查找指定的端口
  4. netstat -ano |findstr 1883
复制代码

②停止端口

  1. # 停用端口
  2. taskkill -PID 8984 -F
  3. # 查看占用此端口的进程,在任务管理器中强制结束
  4. tasklist|findstr 8984
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行