若依前后端分离管理系统的初始化
一、下载若依
https://www.ruoyi.vip/
1.1 打开若依官网,找到源码地址,选择RuoYi-Vue前端分离版,选择发行版,下载Source code (zip)并解压
二、前端部署
2.1 在解压的文件夹RuoYi-Vue-v3.8.7中找到ruoyi-ui,剪切去前端工程目录,在ruoyi-ui中打开控制台输入yarn install安装依赖,如下载错误可设置忽略引擎检查和跳过https证书验证再重试
yarn config set strict-ssl false //将 'strict-ssl' 设置为 false,跳过 HTTPS 证书验证
yarn config set ignore-engines true //忽略引擎检查
2.2 依赖安装完毕后,由于Node版本兼容问题,可以在ruoyi-ui根目录package.json文件中找到scripts,将dev,build:prod,build:stage修改为
"dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build:prod": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
"build:stage": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build --mode staging",
2.3 避免上面出错的方法是使用
npm install --registry=https://registry.npmmirror.com
安装
2.4 在控制台输入yarn dev或者npm run dev即可启动前端项目
2.5 如果还出错就是Node17新的加密政策关系,第一种是安装Node17以前的版本,第二种是在NODE_OPTIONS来兼容旧的加密算法。CMD执行:
set NODE_OPTIONS=--openssl-legacy-legacy-provider
三、数据库导入
3.1 新建数据库ry-vue,在解压的文件中找到sql,导入ry_20231130.sql和quartz.sql
四、后端部署
4.1 打开IDEA,导入项目,选择RuoYi-Vue-v3.8.7文件夹中的pom.xml,等待工程导入完成
4.2 找到ruoyi-admin模块下的配置文件application-druid.yml,将主库数据源中的url,username,password改为自己的数据库信息
4.3 找到ruoyi-admin模块下的配置文件application.yml,将Redis中的host和port改为自己的Redis信息
4.4 启动Redis
4.5 找到ruoyi-admin模块下的RuoYiApplication启动后端项目
五、访问
前端
localhost:80
后端
localhost:8080
六、打包
IDEA=点击右侧的Maven展开Maven管理,选择root>Lifecycle 先双击clean清除原本启动项目时生成的文件。然后点击compile编译,接着点击package等待项目打包,切记要取消运行再打包,打包完成后会在ruoyi-admin>src>target里面看到.jar后缀的文件,就代表打包成功(可以把这个文件复制出来存放到其他地方,方便后面启动)java -jar ruoyi-admin.jar
前端npm run build:prod进行打包,把前端的dist打包文件放进去nginx的html中
nginx设置
#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 80;
server_name localhost;
root html//dist;
# root C://nginx//nginx-1.26.1//html//dist;
#charset koi8-r;
#access_log logs/host.access.log main;
location /{
try_files $uri $uri/ /index.html;
index index.html index.htm;
autoindex on;
}
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://127.0.0.1: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;
# }
#}
}