【问题标题】:Nginx Load Balancing Between Two Static Sites两个静态站点之间的 Nginx 负载平衡
【发布时间】:2022-06-22 06:00:40
【问题描述】:

我在运行 nginx 的同一台服务器上有两个静态(角度)站点,我想在它们之间进行负载平衡。例如:

  • /home/user/app-1
  • /home/user/app-2

负载平衡的所有示例似乎都指向在端口上运行的其他服务器或服务,而不是多个位置。我当前针对单个站点的 nginx 配置:

server {
    listen                    443 ssl http2;
    listen                    [::]:443 ssl http2;
    server_name               domain.com *.domain.com;

    location / {
        root /home/user/app-1;
        index index.html;
        try_files $uri $uri/ /index.html?$args;
    }
}

如何做到这一点?

【问题讨论】:

    标签: nginx load-balancing


    【解决方案1】:
    upstream backend  {
     least_conn;
     server 127.0.0.1:5001 weight=1;
     server 127.0.0.1:5002 weight=1;
    }
    
    server {
        listen                    443 ssl http2;
        listen                    [::]:443 ssl http2;
        server_name               domain.com *.domain.com;
    
        location / {
            proxy_pass http://backend;
        }
    }
    
    
    server {
        listen                    5001 ssl http2;
        listen                    [::]:5001 ssl http2;
        server_name               _;
    
        location / {
            root /home/user/app-1;
            index index.html;
            try_files $uri $uri/ /index.html?$args;
        }
    }
    
    
    server {
        listen                    5002 ssl http2;
        listen                    [::]:5002 ssl http2;
        server_name               _;
    
        location / {
            root /home/user/app-2;
            index index.html;
            try_files $uri $uri/ /index.html?$args;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-04
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 2019-04-05
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      相关资源
      最近更新 更多