博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx + tomcat配置负载均衡
阅读量:7084 次
发布时间:2019-06-28

本文共 1166 字,大约阅读时间需要 3 分钟。

目标:Nginx做为HttpServer,连接多个tomcat应用实例,进行负载均衡。

注:本例程以一台机器为例子,即同一台机器上装一个nginx和2个Tomcat且安装了JDK1.7。

1、安装Nginx

2、配置两个Tomcat

在本机上配置两个Tomcat,分别为tomcat7-8081、tomcat7-8082。
tomcat7-8081访问地址:http://localhost:8081,浏览显示内容:this is 8081 port
tomcat7-8082访问地址:http://localhost:8082,浏览显示内容:this is 8082 port

D:\div\tomcat7-8081\webapps\ROOT\index.jsp文件内容为:

    this is 8081 port

D:\div\tomcat7-8082\webapps\ROOT\index.jsp文件内容为:

    this is 8082 port

这样我们就成功的搭建了一个nginx服务,成功的配置了两个tomcat应用实例。

3、Nginx+Tomcat负载均衡配置

这里只需要修改Nginx的配置,让它通过tomcat来转发。
a、nginx.conf配置文件

worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  10;    include extra/upstream01.conf;}

 

b、extra/upstream01.conf文件,负载均衡配置信息

upstream mysite {    server localhost:8081 weight=5;    server localhost:8082 weight=5;} server {    listen 80;    server_name localhost;      location / {    proxy_pass http://mysite;    }}

当有请求到localhost时,请求会被分发到对应的upstream设置的服务器列表上,每一次请求分发的服务器都是随机的。

接着在运行一次start nginx,当你不断刷新http://localhost的时候,浏览器上就会来回切换"this is 8081 port"和"this is 8082 port"。

这样说明负载均衡配置成功了!!!!!!

转载地址:http://fglml.baihongyu.com/

你可能感兴趣的文章
[状压DP][二分]JZOJ 3521 道路覆盖
查看>>
【错误】 “=” 与 "==" 不分
查看>>
Java技术回顾之JNDI:命名和目录服务基本概念(转)
查看>>
0622 总结与回顾
查看>>
[转]SharePoint 2010 Download as Zip File Custom Ribbon Action
查看>>
面向对象-对象和类
查看>>
ROS系统玩转自主移动机器人(4)-- 嵌入式硬件平台
查看>>
[转]Python 资源大全中文版
查看>>
Unlock PeopleSoft Objects All at Once
查看>>
style定义
查看>>
在服务器上搭建git仓库
查看>>
五子棋js
查看>>
ansible命令
查看>>
六种设计原则
查看>>
怎么查看被占用的端口号
查看>>
输入十个数,最大的数和第最后一个数对换,最小的数和第一个数字对换
查看>>
Linux指令--mv
查看>>
Python中如何实现im2col和col2im函数(sliding类型)
查看>>
IP校验shell脚本
查看>>
软件工程——《你的灯亮着吗》读书笔记
查看>>