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

相关推荐
Hello.Reader1 小时前
NGINX 四层 SSL/TLS 支持ngx_stream_ssl_module
运维·nginx·ssl
极客奇点6 小时前
基于 Nginx 服务器的泛域名 SSL 证书申请与部署
服务器·nginx·ssl
武子康8 小时前
Java-43 深入浅出 Nginx - 基本配置方式 nginx.conf Events块 HTTP块 反向代理 负载均衡
java·后端·nginx·http·负载均衡·运维开发
@阿雄8 小时前
NGINX
服务器·nginx
水煮白菜王1 天前
Nginx攻略
前端·nginx
兲行健1 天前
为 Nginx 配置 HTTPS(以 n8n 为例)完整教程【CentOS 7】
nginx·https·centos
bruce1281 天前
应用无法获取用户真实ip问题排查
nginx·kubernetes·ingress
Smile_Gently2 天前
基于服务器使用 apt 安装、配置 Nginx
nginx·ubuntu·debian
慈云数据2 天前
从零搭建高性能企业级网站:Nginx + PHP-FPM 实战,全程用慈云数据服务器加持
服务器·nginx·php
HGW6892 天前
为什么已经有 Nginx 了,还需要服务网关?
nginx·spring cloud·微服务·架构