• nginx 负载均衡


    三台装有nginx的虚拟机,一台做反向代理服务器,另外两台做真实服务器,模拟负载均衡。

    192.168.13.129       #反向代理服务器
    192.168.13.133       #真实服务器
    192.168.13.139       #真实服务器


    三台服务器的配置

    我们在反向代理服务器上(192.168.13.139)进行如下配置:
    [root@real-server ~]# vim /etc/nginx/conf.d/default.conf
    清空并添加以下内容
    upstream test_server {
          server 192.168.13.133:8080;
          server 192.168.13.139:8080;
        }
     server {
            listen 80;
            server_name localhost;
            location / {
               proxy_pass  http://test_server;
            }
    }
    [root@server ~]# nginx -t
    [root@server ~]# nginx -s reload
    
    第一台真实服务器配置(192.168.13.133):
    [root@real-server ~]# vim /etc/nginx/conf.d/default.conf
    清空并添加以下内容
    server {
            listen 80;
            server_name localhost;
            location / {
                    root    /usr/share/nginx/html/login;
                    index   index.html index.html;
                    }
    }
    [root@real-server ~]# nginx -t
    [root@real-server ~]# nginx -s reload
    #创建目录和文件并写入测试数据
    [root@real-server ~]# mkdir -p /usr/share/nginx/html/login
    [root@real-server ~]# echo "this is first real-server" > /usr/share/nginx/html/login/index.html
    
    第二台真实服务器配置(192.168.13.139):
    [root@real-server ~]# vim /etc/nginx/conf.d/default.conf
    清空并添加以下内容
    server {
            listen 80;
            server_name localhost;
            location / {
                    root    /usr/share/nginx/html/login;
                    index   index.html index.html;
                    }
    }
    [root@real-server ~]# nginx -t
    [root@real-server ~]# nginx -s reload
    #创建目录和文件并写入测试数据
    [root@real-server ~]# mkdir -p /usr/share/nginx/html/login
    [root@real-server ~]# echo "this is second real-server" > /usr/share/nginx/html/login/index.html
    

    测试:打开网页输入反向代理服务器ip:http://192.168.13.129/

  • 相关阅读:
    VS2010和VS2015的Dll项目
    Umbraco遇到的问题解决
    EF Code first 和 DDD (领域驱动设计研究)系列一
    Gulp的学习和使用
    .Net开发中的@ 和 using 使用技巧
    异常基础
    正则表达式
    常用类
    泛型设计中<T> 和<E>的区别
    各个服务器启动命令
  • 原文地址:https://www.cnblogs.com/plyc/p/14253430.html
Copyright © 2020-2023  润新知