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 小时前
【405】Not Allowed
java·vue.js·nginx·node.js
哟哟-2 小时前
Nginx配置:静态文件访问时动态添加时间戳
运维·前端·javascript·nginx
追夢秋陽3 小时前
MacOS 通过Shell 脚本一步到位配置nginx+Php环境
nginx·macos·php·一站式配置
p***19945 小时前
SpringBoot项目中替换指定版本的tomcat
spring boot·后端·tomcat
利刃大大5 小时前
【SpringCloud】负载均衡LoadBalance && SpringCloudLoadBalancer && 多机部署
spring·spring cloud·负载均衡
_codemonster1 天前
配置Tomcat时为啥要配置Artifacts
java·tomcat·firefox
No8g攻城狮1 天前
【Nginx】Nginx实现动态路由映射
运维·nginx
fengsen52113141 天前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
unirst19850071 天前
使用vite打包并部署vue项目到nginx
前端·vue.js·nginx
市安1 天前
基于Debain构建Ngxin镜像
运维·nginx·docker·云原生·容器·debian·镜像