title: nginx configuration to serve multiple sites (subdomains) from same server
body: <p>I would like to serve multiple sites from the same machine.</p>
  
  <p>For each site, I am using nginx listening to a port to communicate with app server (uwsgi) and another port as a proxy server.
  Each site uses uwsgi and flask.</p>
  
  <p>All sites share same API ending point names, so the only difference will be the subdomain name.</p>
  
  <p>Something like this:</p>
  
  <pre><code>server {
  
      listen 8000 default_server;
  
      server_name 00.myexample.com;
  
      ...
  
  }
  
  # Set cache dir
  proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m max_size=50m inactive=60m;
  proxy_cache_key "$scheme$request_method$host$request_uri";
  
  
  # Virtualhost/server configuration
  server {
      listen  80  default_server;
  
      server_name 00.myexample.com;
  
      location / {
  
          proxy_cache my_zone;
          include proxy_params;
          proxy_pass http://00.myexample.com:8000;
      }
  
  ...
  
  }
  </code></pre>
  
  <p>I thought, to replicate multiple sites (00.myexample.com, 01.myexample.com) I would just need to make listen to different ports.</p>
  
  <p>Are <code>server_name</code> and a different ports sufficient to avoid conflicts (e.g. in the cached) ?
  Should also uwsgi listen to different ports for each app ? (it communicate with nginx through socket in the folder of each site, now) </p>
  
  <p>Which configuration would you do to route multiple subdomains to a same machine?</p>