linux安全--Nginx与Tomcat实现负载均衡

目录

1.实验拓扑原理图,前提实现全网互通

2.找到nginx的conf目录中的nginx.conf文件

3.实验效果


1.实验拓扑原理图,前提实现全网互通

搭建全网互通可以看https://blog.csdn.net/m0_74313947/article/details/136008513?spm=1001.2014.3001.5501

搭建Nginx可以看

https://blog.csdn.net/m0_74313947/article/details/136562578?spm=1001.2014.3001.5501

安装Tomcat可以看

https://blog.csdn.net/m0_74313947/article/details/136683374?spm=1001.2014.3001.5501

首先在server1 172.16.1.200,server2 172.16.1.110上安装Tomcat并启动

在server3上安装Nginx并运行

2.找到nginx的conf目录中的nginx.conf文件

XML 复制代码
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{

        server 172.16.1.200:8080 weight=1;
        server 172.16.1.110:8080 weight=1;
    }

---------------------------------------------

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

----------------加上这个-----------------------
        location / {
            proxy_pass http://tomcat;
        }
-----------------------------------------------

        #error_page  404              /404.html;

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

在对应位置加上指定配置就可以实现负载均衡

3.实验效果

在客户端访问Nginx也就是80端口,可以看到服务器返回的是Tomcat的页面并且刷新会在两个服务器之间切换

相关推荐
开发小程序的之朴13 小时前
安企CMS的安装-PHPStudy(小皮面板)部署
windows·mysql·nginx
MMendex13 小时前
Nginx_day4——uWSGI,灰度发布,网站限流限速,Nginx跨域
运维·nginx
明月心9521 天前
https配置
nginx·https配置
Ai拆代码的曹操1 天前
TCP RST 包全链路定位:从 Connection Reset 错误到 Nginx keepalive_timeout 不匹配
网络协议·tcp/ip·nginx
她叫我大水龙1 天前
nginx 编译指南:静态编译 + 动态编译
运维·nginx
Icoolkj1 天前
ICOOLKJ 前后端分离项目完整部署文档(MySQL8.4+Redis+JDK21+Nginx+HTTPS+自动同步演示库)
redis·nginx·https
智码看视界2 天前
Tomcat架构深度拆解:Connector和Container到底怎么配合的?
java·servlet·架构·tomcat·web服务器
qetfw2 天前
CentOS 7 搭建 LVS + Keepalived 高可用负载均衡
linux·centos·负载均衡·lvs
Full Stack Developme2 天前
MyBatis-Plus(MP)AST 抽象语法树 设计原理
java·tomcat·mybatis
遇见小修修2 天前
⚠键盘失灵?5 步自查,不用花钱换新键盘
运维·服务器·数据库·计算机外设·电脑·负载均衡