1、tomcat安装

参考我的另一篇文章

ubuntu安装tomcat7


2、多个tomcat的配置

编辑/etc/tomcat7/service.xml,配置字段Service name 、Connect port、defaulthost、Host name、appBase、prefix

下图分别配置端口分别为8080、8081、8082

其中我删除了大部分注释的内容

apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


3、准备测试页面

cd /var/lib/tomcat7 


sudo cp -r webapps webapps8081

sudo cp -r webapps webapps8081


sudo chown tomcat7:tomcat7 webapps8081

sudo chown tomcat7:tomcat7 webapps8082


sudo vi /var/lib/tomcat/webapps/ROOT/index.html

修改字段<h1>It works 8080!</h1>


sudo vi /var/lib/tomcat/webapps8081/ROOT/index.html

修改字段<h1>It works 8081!</h1>


sudo vi /var/lib/tomcat/webapps8082/ROOT/index.html

修改字段<h1>It works 8082!</h1>


启动tomcat

sudo service tomcat7 start


4、浏览器访问测试

如下图所示

apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


5、安装配置nginx

安装

sudo apt-get install nginx


nginx配置

sudo vi /etc/nginx/nginx.conf

在http {}中添加如下图所示内容

apt-get安装tomcat并测试nginx负载均衡


检查配置文件

sudo nginx -t


启动 

sudo nginx 


检查端口

ps -ef | grep nginx 


netstat -an | grep :18080


这里需要注意的是nginx服务端口不要按照默认的80,因为如果按照默认的端口,则无法跳转到tomcat的页面,一直显示的是nginx的默认页面,具体原因还未找到。


6、浏览器访问测试

http://localhost:18080


刷新页面发现页面在变化

apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


apt-get安装tomcat并测试nginx负载均衡


参考:

http://blog.51cto.com/purplegrape/932811

https://blog.csdn.net/dylanzr/article/details/52135196

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-09-05
  • 2022-12-23
  • 2022-02-05
猜你喜欢
  • 2021-09-10
  • 2022-01-02
  • 2021-11-22
  • 2022-01-14
  • 2021-11-13
  • 2021-09-01
相关资源
相似解决方案