步骤1:负载均衡的概念
步骤2:启动两个Tomcat
步骤3:修改nginx.conf
步骤4:重启nginx并访问

步骤 1 : 负载均衡的概念

负载均衡的概念就是当访问量很大的时候,一个 Tomcat 吃不消了,这时候就准备多个 Tomcat,由Nginx按照权重来对请求进行分配,从而缓解单独一个Tomcat受到的压力

步骤 2 : 启动两个Tomcat

到多个Tomcat下载解压8111和8222两个tomcat,并启动

步骤 3 : 修改nginx.conf

首先增加一个upstream ,用来指向这两个tomcat

upstream tomcat_8111_8222{

server  127.0.0.1:8111 weight=1;

server  127.0.0.1:8222 weight=2;

}

然后修改location,反向代理到上述配置。

    location / {

        proxy_pass http://tomcat_8111_8222;

}

weight表示权重,值越大,被分配到的几率越大。 最大多少呢?我也不知道。。。反正10以内都可以用吧,我想的话~

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

    upstream tomcat_8111_8222{

    server  127.0.0.1:8111  weight=1;

    server  127.0.0.1:8222 weight=2;

    }

    server {

        listen       80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            proxy_pass http://tomcat_8111_8222;

    }

        location ~\.(css|js|png)$ {

            root C:/Users/X7TI/Downloads/tomcat_8111/webapps/ROOT;

    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

步骤 4 : 重启nginx并访问

使用命令 nginx -s reload 重启,然后使劲访问

http://127.0.0.1/login.jsp

此时就可以观察到对jsp的访问,被分配到了不同的 Tomcat上

更多内容,点击了解: https://how2j.cn/k/nginx/nginx-balance/1568.html

Nginx系列教材 (五)- 和Tomcat进行负载均衡相关推荐

  1. nginx 反向proxy多个 tomcat,负载均衡

    负载均衡 一,正向proxy与反向proxynginx 二,nginx安装 三,nginx负载均衡 场景 四,配置nginx访问代理多个tomcat 一,正向proxy与反向proxynginx 正向 ...

  2. Nginx安装使用及与tomcat实现负载均衡

    1. 背景 基于nginx强大的功能,实现一种负载均衡,或是不停机更新程序等.nginx相比大家基本上都知道是什么来头了,具体的文章大家可以去搜索相关文章学习阅读,或是可以查看Nginx中文文档和Ng ...

  3. Nginx+Tomcat服务器负载均衡实践方案

    1.    为何选择Nginx+Tomcat做负载均衡? 1.1. Nginx是什么? Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3 ...

  4. NGINX基于Tomcat配置负载均衡

    NGINX基于Tomcat配置负载均衡 本部署指南说明了如何使用NGINX开源和NGINX Plus在Apache Tomcat TM应用程序服务器池之间平衡HTTP和HTTPS流量.本指南中的详细说 ...

  5. Nginx+Tomcat实现负载均衡、动静分离集群部署

    Nginx+Tomcat实现负载均衡.动静分离集群部署 一.Tomcat多实例部署 1.安装好jdk 2.安装tomcat 3.配置tomcat环境变量 4.修改tomcat2中的server.xml ...

  6. nginx+tomcat的负载均衡

    nginx+tomcat的负载均衡 一. Nginx的安装配置 1. Nginx服务器端 Nginx服务器的IP:192.168.5.108 Tomcat01的IP:   192.168.5.102 ...

  7. nginx+tomcat+memcached负载均衡

    2019独角兽企业重金招聘Python工程师标准>>> nginx+tomcat+memcached负载均衡 负载均衡: 负载均衡是由多台服务器以对称的方式组成一个服务器集合,每台服 ...

  8. nginx+tomcat实现负载均衡集群

    一台tomcat站点由于可能出现单点故障及无法应付过多客户复杂多样的请求等问题,不能单独应用于生产环境下 所以需要一套可靠的解决方案来完善web站点架构 而Nginx只能访问静态页面,如果需要动态需要 ...

  9. nginx+tomcat+redis负载均衡及session共享

    概述 本文档是用来详细描述 nginx+tomcat+redis负载均衡实现session共享 所需软件及下载地址 软件名称 下载地址 功能说明 Nginx-v1.6.0 http://nginx.o ...

  10. Nginx+Tomcat 搭建负载均衡、动静分离(tomcat多实例)

    文章目录 一.Tomcat多实例配置 1.关闭防火墙 2.将软件包上传到/opt目录下 3.安装JDK 4.安装Tomcat 5.配置tomcat环境变量 6.修改tomcat2中的server.xm ...

最新文章

  1. [k8s] 重新加入master节点
  2. [leetcode-61-Rotate List]
  3. HTTP文件浏览(静态文件+express4.x+md/code文件渲染)
  4. 1562: 比较大小(思维)
  5. fc-ae-1553_什么是AE-L,AF-L和*按钮,它们的作用是什么?
  6. Linux基础学习导图
  7. VideoJS - HTML5免费视频播放器源码 支持多格式
  8. 鲁棒性的获得 —— 测试的架构
  9. python识别视频中火焰_监控视频中火焰检测算法
  10. ITIL学习笔记——核心流程之:服务级别管理
  11. android 系统默认字体大小,Android系统默认字体大小
  12. JSON.stringify(value, replacer, space)详解
  13. [人工智能-深度学习-29]:卷积神经网络CNN - 全连接网络与卷积网络结构的互为等效与性能比较
  14. vue数据传递--父传子-方法传递
  15. 远端服务器无响应请检查网络,连接远程服务器超时请检查网络连接
  16. java 服务器文件下载
  17. Kali Linux系统正确完整安装指南教程
  18. iOS第三方插件——Masonry详解
  19. mysql 查询 断号_Mysql断号查询(连续数字查询中间断开的地方)
  20. [BUUCTF-pwn] qwb2018_opm

热门文章

  1. Python(TensorFlow框架)实现手写数字识别系统
  2. 浅尝辄止_数学建模(笔记_系统(层次)聚类算法及其SPSS实现)
  3. mysql数据长度过长,1406 - Data too long for column ‘express_company‘ at row 1
  4. Oracle11g-linux安装
  5. netty 错误 #[IllegalReferenceCountException: refCnt: 0, decrement: 1]
  6. 【数据库和SQL学习笔记】6.SELECT查询4:嵌套查询、对查询结果进行操作
  7. rmmod命令卸载驱动后重启后为什么驱动还在? 安排!
  8. Android-NuPlayer音视频同步之安卓Q新功能
  9. Python工具函数
  10. oracle operation_type,案例:Oracle报错performing DML/DDL operation over object in bin解决办法