Nginx的负载均衡

1、安装ubuntu环境和redhat环境

【Tools】Ubuntu22.04安装详细教程_ubuntu22.04安装教程-CSDN博客(侵权必删)

2、构建Nginx环境

Nginx快速入门-KuangStudy-文章

3、ngnix常用命令:

复制代码
cd /usr/local/nginx/sbin/
./nginx  启动
./nginx -s stop  停止
./nginx -s quit  安全退出
./nginx -s reload  重新加载配置文件
ps aux|grep nginx  查看nginx进程

4、检查ngnix环境配置

在192.168.118.131服务器下:

在192.168.118.128下:

5、实现nginx负载均衡所添加的代码:

复制代码
    upstream nginx_boot{
   # 30s内检查心跳发送两次包,未回复就代表该机器宕机,请求分发权重比为1:2
   	server 192.168.118.128 weight=100 max_fails=2 fail_timeout=30s; 
   	server 192.168.118.131 weight=200 max_fails=2 fail_timeout=30s;
   # 这里的IP请配置成你WEB服务所在的机器IP
	    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;    
	        index  index.html index.htm index.jsp index.ftl;
       	    proxy_set_header Host $host;
       	    proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 请求交给名为nginx_boot的upstream上
            proxy_pass http://nginx_boot;
        }

6、测试:

第一次轮播:界面是nihao!

第二次轮播:界面是nnn

相关推荐
q***d1736 小时前
前端微前端部署方案,Nginx与Webpack
前端·nginx·webpack
代码炼金术士10 小时前
linux的nginx版本升级
linux·运维·nginx
CXH72814 小时前
nginx-file-server
运维·数据库·nginx
寺中人14 小时前
Nginx安全策略
运维·nginx
橘色的喵17 小时前
C语言面向对象范式:Nginx模块化架构的设计分析
c语言·nginx·架构·面向对象
百***67031 天前
Nginx搭建负载均衡
运维·nginx·负载均衡
m0_569531011 天前
Nginx(4)--Nginx与tomcat反向代理和负载均衡
nginx·tomcat·负载均衡
R.lin2 天前
浅谈Nginx
运维·nginx
Crazy________2 天前
37负载均衡介绍和nginx模块编译安装
运维·nginx·负载均衡
百***34132 天前
Nginx实现接口复制
运维·nginx·junit