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

相关推荐
鬼才血脉8 小时前
Idea使用Tomact运行项目,控制台输出中文乱码
tomcat·bug
彦楠11 小时前
指定Tomcat运行的JDK地址
java·开发语言·tomcat
難釋懷12 小时前
Nginx高可用配置
linux·nginx·php
x***r15113 小时前
linux安装 apache-tomcat-7.0.42.tar.gz 详细步骤(解压、配置、启动)
linux·tomcat·apache
风曦Kisaki14 小时前
Nginx代理与LVS(NAT/DR)全方位对比
运维·nginx·lvs
sinat_2554878115 小时前
HTTP、端口、请求、响应、REST
java·网络·网络协议·http·tomcat·intellij-idea
難釋懷1 天前
Nginx防盗链配置
运维·nginx
Nian.Baikal1 天前
从零搭建离线地图服务:Nginx + Cesium/Leaflet 实战指南
运维·前端·nginx
身如柳絮随风扬1 天前
Docker 部署 Nginx:从入门到生产级配置实战
nginx·docker·容器
夏天测1 天前
【高危漏洞通告】NGINX ngx_http_rewrite_module 堆缓冲区溢出漏洞;详解与修复方案
运维·nginx·http