Apache Configuration
(Monitor intranet IP and port)
Listen 10.163.170.8:8001Listen10.163.170.8:8002Listen10.163.170.8:8003<virtualhost *:8001> documentroot/website/111. com ServerName localhost:8001directoryindex 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:8002directoryindex 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:8003directoryindex index.html index.php errorlog logs/333. Com-error_log Customlog logs/333. Com-access_log common</virtualhost>
Nginx Configuration
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_timeout0;Keepalive_timeout 65;#gzip on;# Load config files from the/etc/nginx/conf.d directory # The default server was 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 test
(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);functionTest$url){ $data=file_get_contents($url); return Trim($data);}?>
Test Results 1
Array (3) { [222]=> int (over) [ 333 ]=> int ($) [111]=> Int ()}
Test Results 2
Array (3) { [333]=> int (Wuyi) [ 222]=> int (+) [111]= > int (+)}
Nginx Apache load Balancing test