配置nginx负载均衡


server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

if ($request_uri ~* \.html$){

#html后缀访问 htmlservers 服务器池

proxy_pass http://htmlservers;

}

if ($request_uri ~* \.php$){

#php后缀访问 phpservers 服务器池

proxy_pass http://phpservers;

}

#默认访问服务器池

proxy_pass http://picservers;

}

}


#配置服务器池

upstream htmlservers {

server 192.168.2.62:80;

server 192.168.2.69:80;

}

upstream phpservers {

server 192.168.2.63:80;

server 192.168.2.65:80;

}

upstream picservers {

server 192.168.2.66:80;

server 192.168.2.68:80;

}