ps(2台虚拟机虚拟机1安装nginx和vue前端打包代码ip后缀 .9 是1,
虚拟机2安装mysql,jdk,tomcat,后端带包代码ip后缀.10是虚拟机二)
1、前端模块部署
将前端模块打包,生成dist文件夹,需要将它上传到nginx服务器
1)上传dist文件
2)移动到html目录下
[root@fys1 html]# mv /root/dist/ /usr/local/nginx/html/
3)修改nginx.conf 如下配置
location / {
root html/dist;
index index.html index.htm; }
4)重启nginx [root@fys1 conf]# systemctl restart nginx
2、后端模块部署
将后端模块打包,生成jar包或者war包,需要将它上传到tomcat服务器 备注:
sringboot自带tomcat,所以打包后需要看一下,有没有将tomcat也打包进去,此次 上机任务使用外置的tomcat,打包时不要将tomcat打包进去
pom.xml添加以下内容:
org.springframework.boot
spring-boot-starter-tomcat
provided
application-druid.yml 修改mysql的ip配置
application.yml 修改redis的ip地址
部署:
1)上传war包(没有tomcat环境的,使用我们自己部署的外置tomcat)
2)将war包移动到tomcat中
[root@localhost ~]# mv ruoyi.war /root/apache-tomcat-9.0.11/webapps/
3)配置mysql库和表
4)测试redis可不可以
[root@localhost ~]# cat /etc/redis.conf | grep -v "#" | egrep "protect|bind"
bind 0.0.0.0
protected-mode no
重启redis服务
[root@localhost ~]# redis-server /etc/redis.conf
[root@localhost ~]# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 7975/redis-server 0
修改tomcat配置文件,希望访问/路径直接访问到若依的资源
<Context path="/" docBase="/root/apache-tomcat-9.0.11/webapps/ruoyi"
reloadable="false"></Context>
6)重启tomcat服务
systemctl restart tomcat
7)网页访问
访问:http://loaclhost:8080/ 出现以下内容即可,因为若依有登录界面,没有前端登录所以认证失败
{"msg":"请求访问:/,认证失败,无法访问系统资源","code":401}
8)配置mysql库和表
9)配置nginx反向代理
1)修改nginx配置文件,添加以下内容
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://192.168.174.10:8080/;
}
2)重启nginx systemctl restart nginx
3)网页访问
http://192.168.174.9/