-
前期准备
- 安装nginx(我前面的博客有说明)
- 安装apache-tomcat-7.0.47.tar.gz
-
过程步骤
- 解压apache-tomcat-7.0.47.tar.gz,tar -zxvf apache-tomcat-7.0.47.tar.gz,
- 重命名,mv apache-tomcat-7.0.47 apache-tomcat-sina
- 复制apache-tomcat-sina,命令:cp -r apache-tomcat-sina apache-tomcat-sina2
- 复制apache-tomcat-sina,命令:cp -r apache-tomcat-sina apache-tomcat-sohu
- 修改apache-tomcat-sina/webapps/ROOT/index.jsp文件,将后面加上-sina,如下图:

- 同理,也修改apache-tomcat-sina2/webapps/ROOT/index.jsp文件,后面加上-sina2
- 也修改apache-tomcat-sohu/webapps/ROOT/index.jsp文件,后面加上-sohu
- 修改apache-tomcat-sohu/conf/server.xml配置文件,修改相对应的端口,将8005改为8006,将8080改为8081,将8009改为8010
- 修改apache-tomcat-sina/conf/server.xml配置文件,修改相对应的端口,将8005改为8007,将8080改为8082,将8009改为8011
- 启动tomcat,通过浏览器访问http://ip:8080,http://ip:8081,http://ip:8082
- 修改nginx.conf配置文件,如下:
upstream sina{ server 192.168.1.107:8080; server 192.168.1.107:8082 weight=2; } server { listen 80; server_name www.sina.com.cn; location / { proxy_pass http://sina; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream sohu{ server 192.168.1.107:8081; } server { listen 80; server_name www.sohu.com; location / { proxy_pass http://sohu; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } -
修改windows系统中的host文件,该文件在C:\Windows\System32\drivers\etc该路径下,如下:
192.168.1.107 www.sina.com.cn 192.168.1.107 www.sohu.com你在浏览器上访问www.sina.com.cn,请求就回到192.168.1.107服务器地址上了,nginx就会根据域名重新找服务器
nginx反向代理和负载均衡搭建与测试
最新推荐文章于 2021-06-07 23:23:15 发布
本文详细介绍如何使用Nginx实现对多个Apache Tomcat服务器的负载均衡,包括Tomcat的安装与配置、Nginx配置修改以及Windows系统中host文件的设置,确保网站访问稳定性和高可用性。
341

被折叠的 条评论
为什么被折叠?



