nginx apache負載平衡測試

來源:互聯網
上載者:User

標籤:

apache配置

(監聽內網ip和連接埠)

Listen 10.163.170.8:8001Listen 10.163.170.8:8002Listen 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."\n");    $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)}

 

nginx apache負載平衡測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.