第一种部署方案: 把前后端项目,分别放在一台tomcat和nginx中,然后将tomccat和nginx放在云服务器中.
一.tomcat配置后端
将foodie-shop拖到/usr/local/nginx目录下
 /usr/local/nginx/foodie-shop/js目录下的app.js配置如下:


nginx目录下的conf文件夹下的nginx.conf文件配置如下:

 改完再重新加载文件,命令如下
/usr/local/nginx/sbin/nginx -s reload
输入地址192.168.0.115:88测试前端页面是否打开

二.tomcat配置后端
进入/software/tomcat/apache-tomcat-9.0.44/webapps/manager/META-INF文件下的context.xml文件
 把value里的内容注释掉如下:
 在:/software/tomcat/apache-tomcat-9.0.44/conf目录下的tomcat-users.xml中添加如下内容:

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="root" password="root" roles="manager-gui,admin-gui"/>
进入Manager App页面

选择要部署项目的war包

测试后端项目是否能启动

测试数据库是否连接

前后端页面联通如下:

第二种部署方案: 并发量上来了,把前后端项目,分别放在两台tomcat和nginx中,然后将tomccat和nginx放在云服务器中,让nginx负载均衡分别请求两台tomcat.
把在/usr/local/nginx/conf目录下的nginx.conf添加如下内容(红色部分):

 在/usr/local/nginx/foodie-shop/js下的app.js文件的生产环境修改如下:


再输入如下命令进入,在按钮button中加入IP号(方便区分两台tomcat)如下:
vim /software/tomcat/apache-tomcat-9.0.44/webapps/ROOT/index.jsp

输入IP192.168.0.115:99 测试两台tomcat是否联通:
 Ctrl+F5刷新

|