• nginx apache负载均衡测试


    apache配置

    (监听内网ip和端口)

    Listen 10.163.170.8:8001
    Listen 10.163.170.8:8002
    Listen 10.163.170.8:8003
    
    <VirtualHost *:8001>
        DocumentRoot /website/111.com
        ServerName localhost:8001
        DirectoryIndex index.html index.php
        ErrorLog logs/111.com-error_log
        CustomLog logs/111.com-access_log common
    </VirtualHost>
    
    <VirtualHost *:8002>
        DocumentRoot /website/222.com
        ServerName localhost:8002
        DirectoryIndex index.html index.php
        ErrorLog logs/222.com-error_log
        CustomLog logs/222.com-access_log common
    </VirtualHost>
    
    <VirtualHost *:8003>
        DocumentRoot /website/333.com
        ServerName localhost:8003
        DirectoryIndex index.html index.php
        ErrorLog logs/333.com-error_log
        CustomLog logs/333.com-access_log common
    </VirtualHost>

    nginx配置

    http {
        include       /etc/nginx/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  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
        
        # Load config files from the /etc/nginx/conf.d directory
        # The default server is in conf.d/default.conf
        # include /etc/nginx/conf.d/*.conf;
    
        upstream webservers {
            server 10.163.170.8:8001 weight=1;
            server 10.163.170.8:8002 weight=2;
            server 10.163.170.8:8003 weight=3;
        }
    
        server {
            listen    80;
            server_name  localhost;
            location / {
                proxy_pass      http://webservers;
                proxy_set_header  X-Real-IP  $remote_addr;
            }
        }
    
    }

    php测试

    (nginx_upstream_test.php)

    <?php
    $url = 'http://114.215.107.17/';
    $count = 100;
    
    $webservers = array();
    for($i=1; $i<=$count; $i++){
        echo($i."
    ");
        $data = test($url);
        $webservers[$data]++;
    }
    var_dump($webservers);
    
    function test($url){
        $data = file_get_contents($url);
        return trim($data);
    }
    ?>

    测试结果1

    array(3) {
      [222]=>
      int(34)
      [333]=>
      int(49)
      [111]=>
      int(17)
    }

    测试结果2

    array(3) {
      [333]=>
      int(51)
      [222]=>
      int(33)
      [111]=>
      int(16)
    }
  • 相关阅读:
    pytorch
    leetcode686 C++ 20ms 重复叠加字符串匹配 没啥意思
    leetcode680 C++ 124ms 删掉一个字符后能否构成回文
    leetcode58 C++ 4ms 最后一个单词的长度
    leetcode14 C++ 8ms 最长公共前缀
    leetcode20 C++ 4ms 有效的括号 微软面试题
    leetcode387 C++ 84ms 字符串中的第一个唯一字符
    leetcode459 C++ 32ms 重复子串构成的字符串
    leetcode383 C++ 36ms 赎金信
    leetcode345 C++ 12ms 反转字符串中的元音
  • 原文地址:https://www.cnblogs.com/coffee_cn/p/4269686.html
Copyright © 2020-2023  润新知