一、配置轮询的负载均衡
在ngnix.conf中配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#配置多台服务器
upstream yaya{
server 192.168.200.131:80;
server 192.168.200.132:80;
}
server {
listen 80;
server_name localhost;
location / {
#代理到服务器
proxy_pass http://yaya;
# root html;
#index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
二、配置权重的负载均衡
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#配置多台服务器
upstream yaya{
#weight表示权重的比例,down表示不参与服务,backup表示备用服务器
server 192.168.200.131:80 weight=7 down;
server 192.168.200.132:80 weight=2;
server 192.168.200.133:80 weight=1 backup;
}
server {
listen 80;
server_name localhost;
location / {
#代理到服务器
proxy_pass http://yaya;
# root html;
#index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}