nginx负载均衡

upstream tornado_servers {
    least_conn;  # 使用最少连接数算法
    server 192.168.31.158:8888 weight=5;
    server localhost:8888 weight=3;
}

server {
    listen 80;
    server_name 192.168.62.132; 

    location / {
        proxy_pass http://tornado_servers;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /nginx_status {
    stub_status on;
    access_log off;
    allow 192.168.62.0/24;  # 允许访问的IP地址,根据需要调整
    deny all;         # 禁止其他IP地址访问
    }
}

  

upstream tornado_servers {
    ip_hash;  # 使用IP哈希算法
    server 192.168.31.158:8888;
    server localhost:8888;
}

server {
    listen 80;
    server_name 192.168.62.132;  

    location / {
        proxy_pass http://tornado_servers;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /nginx_status {
    stub_status on;
    access_log off;
    allow 192.168.62.0/24;  # 允许访问的IP地址,根据需要调整
    deny all;         # 禁止其他IP地址访问
    }
}

  

posted @ 2024-06-13 20:54  青山下  阅读(13)  评论(0编辑  收藏  举报