title: Run multiple independent Flask apps in Ubuntu
body: <p>I'm trying to run two or more Flask applications in separate virtual directories with Apache, like <code>http://localhost/site1</code> for <em>/var/www/myapps/app1</em> and <code>http://localhost/site2</code> for <em>/var/www/myapps/app2</em>. Each app has its own virtual environment under an <em>env</em> directory.</p>
  
  <p>I started with a fresh install of Ubuntu 14.04 with Apache2 (v2.4.7), removed the default site configuration with <code>sudo a2dissite 000-default</code> and added configuration for my two apps. </p>
  
  <p>Here's the conf file for app1 at <em>/etc/apache2/sites-available/app1.conf</em>. The cofiguration for app2 is identical, replacing <code>app2</code> for <code>app1</code> (and <code>site2</code> for <code>site1</code>.)</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName localhost
      WSGIProcessGroup site1
      WSGIDaemonProcess site1 user=myserviceuser group=myserviceuser threads=5 python-path=/var/www/myapps/app1:/var/www/myapps/app1/env/lib/python2.7/site-packages
      WSGIScriptAlias /site1 /var/www/myapps/app1/application.wsgi
      WSGIScriptReloading On
      &lt;Directory /var/www/mysites/app1&gt;
          WSGIApplicationGroup site1
          Order deny,allow
          Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Then I enabled each site with <code>sudo a2ensite app1</code> (and app2) then restarted the server with <code>sudo apache2ctl restart</code>.</p>
  
  <p>Each of these apps has the following <code>application.wsgi</code> file in the root dir:</p>
  
  <pre><code># put a copy of this file in the root dir of each app instance
  import os, sys
  # activate the virtual environment
  app_dir = os.path.dirname(__file__)
  # removed next two lines after a comment left below
  # activate_this = os.path.join(app_dir, 'env', 'bin', 'activate_this.py')
  # execfile(activate_this, dict(__file__=activate_this))
  sys.path.insert(0, app_dir)
  from myapp import app as application
  </code></pre>
  
  <p>What happens is that one of the sites runs fine, responding with the correct page when I hit it. The other gives me an Apache 404 page. There are no typos in the conf files.</p>
  
  <p>It seems the configurations for the apps are clobbering each other and one is "winning." I've spent a lot of time tweaking the configurations but the only way I could make it work was if I added <strong>localhost2</strong> to my <em>hosts</em> file and changed the <code>ServerName</code> to <code>localhost2</code> in one of the app configs, which isn't desirable in my case. Can someone point me to the correct way to configure Apache? Or am I going the wrong way about this?</p>
  
  <p>Ideally I'd want the configuration files to not care which host name was used to reach them, probably becoming multiple copies of this server running behind a load balancer. </p>