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

相关推荐
终端行者1 天前
Nginx四层负载均衡配置 Stream模块使用
运维·nginx·负载均衡
计算机学姐1 天前
基于SpringBoot的在线骑行网站系统
java·vue.js·spring boot·后端·mysql·spring·tomcat
凸头1 天前
Nginx配置学习
运维·学习·nginx
风若飞1 天前
Linux 环境下解决 Tomcat8 与 JDK8 配置问题
java·linux·运维·服务器·tomcat
南梦浅1 天前
Flask+Gunicorn+Nginx 校园众筹项目部署全流程(生产环境)
nginx·flask·gunicorn
卿着飞翔1 天前
win11安装配置nginx并部署ruoyi前端
运维·前端·nginx
xiaobangsky1 天前
使用Nginx配置本地静态资源iscweb访问后端服务fs-isc
运维·nginx
专家大圣1 天前
Tomcat+cpolar 让 Java Web 应用跨越局域网随时随地可访问
java·前端·网络·tomcat·内网穿透·cpolar
程序员老徐1 天前
Spring Security 是如何注入 Tomcat Filter 链的 —— 启动与请求源码分析
java·spring·tomcat