【问题标题】:Test load balancing on single server with nginx and IIS使用 nginx 和 IIS 在单个服务器上测试负载平衡
【发布时间】:2017-08-07 15:15:30
【问题描述】:

我想用 nginx 和 IIS 在单个服务器上测试负载平衡。 我设置 nginx 监听 localhost:90 和 IIS 上的两个网站监听 localhost:81 和 localhost:82

这是我的nginx.conf

events {
worker_connections  1024;
}

http {
  upstream backend {
    server localhost:81;
    server localhost:82;
  }

  server {
    listen 90;
    server_name backend;
    location / {
      proxy_pass http://localhost:80;
    }
  }
}

当我在浏览器上打开 http://localhost:90 时,它返回 504 Gateway Time-out。

实际上请求将发送到端口 80(我在 proxy_pass 中设置)而不是端口 81 和 82

我知道负载平衡适用于我们有多个服务器的情况。 但是有什么方法可以在具有多个端口的单个服务器上测试负载平衡?

【问题讨论】:

    标签: iis nginx load-balancing


    【解决方案1】:

    将您的配置更改为:

    events {
    worker_connections  1024;
    }
    
    http {
      upstream backend {
        server localhost:81;
        server localhost:82;
      }
    
      server {
        listen 90;
        server_name _;
        location / {
          proxy_pass http://backend;
        }
      }
    }
    

    现在在端口 90 上打开 localhost

    说明:

    要使用 http 块中指定的上游,您需要使用其名称。

    proxy_pass http://backend;
    

    在进行反向代理时设置以下标头也是一个好习惯(因此后端获取客户端信息而不是反向代理服务器):

    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-User  $remote_user;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 2011-07-16
      • 2014-08-29
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多