weight是权重,权重越大,被访问的次数越多,权重分配建议给性能更强的服务器分配更大的权重,配置一样不建议更改权重。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#监听浏览器访问localhost:80端口的服务
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#轮询访问81、82端口
upstream demo {
server localhost:81 weight=1;
server localhost:82 weight=1;
}
#监听浏览器访问localhost:8080端口的服务
server {
listen 8080;
server_name localhost;
location / {
#必须加http://变量名,变量名必须在server外面,http{}里面定义upstream 变量名
proxy_pass http://demo;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}