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的页面并且刷新会在两个服务器之间切换

相关推荐
钱栈up11 小时前
现场部署6个服务菜单全挂:根因不在后端,在前端那个环境变量
mysql·nginx
Csvn19 小时前
Nginx 故障案例库:16 张卡的现象、证据、根因与防复发
后端·nginx
梅雅达编程笔记1 天前
开发机能跑,服务器上跑不起来:MYD 考试系统配置设计与上线清单
mysql·nginx·flask·gunicorn·毕设项目·部署上线
op_qo2 天前
写了几年 OpenResty Lua 网关脚本,聊聊绕不开的 5 个痛点与一种新解法
nginx
Johny_Zhao3 天前
Keepalived与Nginx架构选型
linux·nginx·信息安全·云计算·apache·shell·yum源·keepalive·系统运维
Csvn3 天前
Nginx 可观测性与工程化:指标、告警与发布回滚演练
后端·nginx
Csvn4 天前
Nginx 高可用网关:VIP 切换、proxy_protocol 与 SNI 分流实战
后端·nginx
wno7044 天前
Nginx代理MySQL或PG连接
运维·mysql·nginx
Csvn5 天前
Nginx 性能调优与压测:连接账本、找拐点与调优前后对比
后端·nginx
洋不写bug5 天前
SpringMVC(一) Lifecycle面板|MVC架构|@RequestMapping注解解析
架构·tomcat·mvc·javaee·requestmapping·lifecycle面板·maven项目