title: How do I load 2 flask apps to serve 2 subdomains for nginx/uwsgi using unix sockets?
body: <p>I am following <a href="https://uwsgi.readthedocs.org/en/latest/Nginx.html#virtual-hosting" rel="nofollow">this uwsgi guide</a> to setting up <code>nginx/uwsgi</code> to have 1 flask app run the "www" subdomain and another flask app to run the "api" subdomain. My <code>nginx.conf</code>:</p>
  
  <pre><code>worker_processes  1;
  
  events {
      worker_connections  1024;
  }
  
  http {
      access_log  /path/to/access_nginx.log combined;
      error_log   /path/to/error_nginx.log  crit;
  
      include mime.types;
      sendfile on;
  
      server {
      server_name   api.example.com;
          listen 14265;
  
          location / {
          include uwsgi_params;
          uwsgi_param UWSGI_SCRIPT wsgi_api;
          uwsgi_pass unix:///path/to/api.sock;
          }
      }
  
      server {
      server_name   www.example.com;
          listen 14265;
  
          location / {
              include uwsgi_params;
              uwsgi_param UWSGI_SCRIPT wsgi;
              uwsgi_pass unix:///path/to/wsgi.sock;
          }
      }
  }
  </code></pre>
  
  <p>For starting uwsgi, I do:</p>
  
  <pre><code>#!/bin/bash
  APPNAME=nginx
  # Start uwsgi
  ${HOME}/webapps/${APPNAME}/bin/uwsgi \
    --uwsgi-socket "${HOME}/webapps/${APPNAME}/wsgi.sock" \
    --master \
    --workers 1 \
    --max-requests 10000 \
    --harakiri 60 \
    --daemonize ${HOME}/webapps/${APPNAME}/uwsgi.log \
    --pidfile ${HOME}/webapps/${APPNAME}/uwsgi.pid \
    --vacuum \
    --python-path ${HOME}/webapps/${APPNAME}
  
  # Start nginx
  ${HOME}/webapps/${APPNAME}/bin/nginx
  </code></pre>
  
  <p>When I visit <code>www.example.com</code> it works as expected. However, I get a 502 error for <code>api.example.com</code>. To fix the 502 error I can change <code>api.sock</code> to <code>wsgi.sock</code> in my <code>nginx.conf</code> but it will give me the page for <code>www.example.com</code> when I visit <code>api.example.com</code> (even though <code>wsgi.py</code> and <code>wsgi_api.py</code> are different).</p>
  
  <p>EDIT: The examples I have found for setting up multiple subdomains on nginx/uwsgi (including the one I linked to) all show how to do subdomains with static sites. I cannot find one that shows how to do it with unix sockets.</p>