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

相关推荐
2401_834636998 小时前
Nginx 从入门到实战:静态 / 动态站点、PHP 部署与反向代理全解析
运维·nginx·php
回忆2012初秋11 小时前
【Nginx】优雅地走进高性能 Web 服务器世界(1)
服务器·前端·nginx
難釋懷13 小时前
Nginx-KeepAlive
运维·nginx
2401_8346369913 小时前
Keepalived + LVS (DR) + Nginx + NFS 高可用 Web 集群部署实战手册
前端·nginx·lvs
NCU_wander21 小时前
LB HA(high avaliablity)和nginx
运维·nginx
Pearson1 天前
特大pdf文件在线预览技术方案
javascript·nginx·pdf
難釋懷1 天前
Nginx测试工具charles
运维·nginx·php
我登哥MVP1 天前
SpringCloud 核心组件解析:服务调用和负载均衡
java·spring boot·后端·spring·spring cloud·java-ee·负载均衡
江华森1 天前
Tomcat 10 实战部署指南:从零到生产级 Web 容器
java·前端·tomcat
sbjdhjd1 天前
企业级 Tomcat (上):WEB 技术栈 + 架构演进 + 生产级安装部署
linux·运维·云原生·开源·tomcat·云计算·负载均衡