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

相关推荐
cnskylee7 小时前
【Nginx】Nginx-1.28.1版本已恢复对CentOS 7的兼容性
运维·nginx·centos
毕设源码-郭学长7 小时前
【开题答辩全过程】以 共享单车后台管理系统为例,包含答辩的问题和答案
java·开发语言·tomcat
程序员阿鹏1 天前
责任链模式
java·spring·servlet·tomcat·maven·责任链模式
Knight_AL1 天前
Docker 中的端口映射原理:为什么 Nginx 要 `listen 80`,而不是“随便写端口”
nginx·docker·容器
云老大TG:@yunlaoda3601 天前
华为云国际站代理商NAT的高可用与弹性具体是如何实现的?
服务器·数据库·华为云·负载均衡
虹梦未来1 天前
【运维心得】Ubuntu2404编译nginx隐藏Server信息
运维·服务器·nginx
计算机学姐1 天前
基于php的非物质文化遗产推广系统
开发语言·vue.js·mysql·tomcat·php·postman
tgethe1 天前
Nginx笔记
运维·笔记·nginx
计算机毕设指导61 天前
基于微信小程序的派出所业务管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·uniapp
invicinble1 天前
对于nginx(一,认识nginx)
运维·nginx