nginx负载轮询
下面是一个可以使用nginx负载轮询,如果有一台服务器连接不通,返404,500,502,503,504,会自动切换到下一台服务器
upstream www {
server 111.111.111.2 max_fails=1;
server 111.111.111.3 max_fails=1;
}
server {
listen 80;
server_name $host;
location / {
proxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504;
proxy_pass http://www;
proxy_set_header Host $HOST;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_send_timeout 10;
}
}