title: NGINX Load balancing config for multiple websites
body: <p>I have a NGINX load balancer, with two webservers behind it. Both of them have similar content - hosting similar apps on different domains. Right now my config looks like this:</p>
  
  <pre><code>upstream  foosite  {
      ip_hash;
      server   11.222.33.444;
      server   555.666.777.888;
  }
  
  upstream  barsite  {
      ip_hash;
      server   11.222.33.444;
      server   555.666.777.888;
  }
  
  upstream  bazsite  {
      ip_hash;
      server   11.222.33.444;
      server   555.666.777.888;
  }
  
  server {
      listen 80;
      server_name foosite.*;
  
      location / {
          proxy_pass http://foosite;
          proxy_redirect off;
          proxy_buffering off;
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP       $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
  server {
      listen 80;
      server_name barsite.*;
  
      location / {
          proxy_pass http://barsite;
          proxy_redirect off;
          proxy_buffering off;
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP       $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
  server {
      listen 80;
      server_name bazsite.*;
  
      location / {
          proxy_pass http://bazsite;
          proxy_redirect off;
          proxy_buffering off;
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP       $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
  </code></pre>
  
  <p>Here are the quiestions:</p>
  
  <p>1) Will this config work for multiple top level domains ? Like foosite.com, foosite.org, foosite.net etc ?</p>
  
  <p>2) How can I enable subdomains for all these webistes ? For instance test.foosite.com, admin.foosite.com without making the whole thing too verbose ?</p>
  
  <p>3) It looks like this config can be written wiht less lines of code, how can I merge all 3 upstream definitions into 1, how can I merge 3 server blocks into 1 ?</p>
  
  <p>Thanks in advance. </p>