反向代理
代理多个端口
server{
listen 80;
charset utf-8;
server_name 39.107.221.63;
location ~ /demo/ {
proxy_pass http://39.107.221.63:8080;
proxy_redirect default;
}
location ~ /test/ {
proxy_pass http://39.107.221.63:8081;
proxy_redirect default;
}
}
负载均衡
需要更改的地方
分配服务器策略:轮询(默认),
weight的值越大分配的服务器越多(写在ip地址后),
ip_hash按照ip的hash值的分配(写在location第一行),
fair(第三方)写在location最后一行,根据响应时间分配,时间短的优先分配
upstream myserver{
server 39.107.221.63:8080;//weight=? 设置权重
server 39.107.221.63:8081;
}
location / {
proxy_pass http://myserver;
index index.html index.htm
}