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

相关推荐
unDl IONA21 小时前
服务器部署,用 nginx 部署后页面刷新 404 问题,宝塔面板修改(修改 nginx.conf 配置文件)
运维·服务器·nginx
splage1 天前
Nginx 反向代理之upstream模块以及完整配置反向代理示例
git·nginx·github
hINs IONN1 天前
RabbitMQ HAProxy 负载均衡
rabbitmq·负载均衡·ruby
Tisfy1 天前
CORS 跨域重定向后 Origin 变 null —— 一次 Nginx 字体加载失败的排查记录
运维·nginx·html·cors
福大大架构师每日一题1 天前
nginx 1.30.0稳定版深度解析:Early Hints、HTTP/2后端、MPTCP全量上线,1.29.x分支精华全面整合
运维·nginx·http
繢鴻1 天前
Nginx 配置顺序错误
运维·nginx·阿里云·持续部署
我登哥MVP1 天前
【SpringMVC笔记】 - 8 - 文件上传与下载
java·spring boot·spring·servlet·tomcat·maven
Pocker_Spades_A1 天前
每天刷十几个平台的热榜太累了?我用一个页面全部搞定
nginx
Jaygee-1 天前
个人网盘越来越贵?我用 Nginx 自建了一个 WebDAV
运维·nginx
农村小镇哥2 天前
nginx服务器的介绍
运维·服务器·nginx