RHEL7下Nginx负载均衡配置
前面两节讲过安装和配置文件了,这里写出配置文件,大家根据内容修改配置文件就可以了。
http {
upstream myserver{
server 192.168.1.21:80 weight=2 max_fails=3 fail_timeout=20s;
server 192.168.1.22:80 weight=3 max_fails=3 fail_timeout=20s;
server 192.168.1.23:80 weight=4 max_fails=3 fail_timeout=20s;
}
server{
listen 80;
server_name 192.168.1.20;
index index.htm index.html;
root /application/nginx/html/
location / {
proxy_pass http://myserver;
prox_next_upstream http_500 http_502 http_503 error timeout invalid_header;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_body_buffer_size 128k;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
}