How to host multiple flask apps under a single domain hosted on nginx?
<p>What I am trying to achieve:</p>

<p>I have an nginx web server hosting mydomain.com. When someone types my domain.com into their client I would like my server to serve index.html from <code>/var/www/mydomain/</code> When they type mydomain.com/flaskapp1 they should see flaskapp1. When they type mydomain.com/flaskapp2 they should see flaskapp2.</p>

<p>I have managed to get one or the other flask apps served using the tutorial here <a href="http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/" rel="noreferrer">http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/</a> but when trying to implement serving two separate flask apps I run into difficulty. Instead of seeing the flask app I get a 404 message when I try to access either of the flask apps with mydomain.co.uk/flaskapp or mydomain.co.uk/flaskapp2 in a browser. </p>

<p>This is what I have so far:</p>

<p><strong>cat /etc/nginx/sites-available/mydomain.co.uk</strong></p>

<pre><code>server {
       listen 80;

        server_name www.mydomain.co.uk mydomain.co.uk;

        location / {
               root /var/www/html/;
               index index.html index.htm;
        }

        location /flaskapp {
                include uwsgi_params;
                uwsgi_pass unix:/tmp/flaskapp.sock;
        }

         location /flaskapp2 {
              include uwsgi_params;
              uwsgi_pass unix:/tmp/flaskapp2.sock;
         }
 }
</code></pre>

<p>The above conf file has been sim linked into <code>/etc/nginx/sites-enabled</code>.</p>

<p><strong>cat /etc/uwsgi/apps-available/flaskapp.ini</strong></p>

<pre><code>[uwsgi]
vhost = true
socket = /tmp/flaskapp.sock
venv = /var/www/flaskapp/venv
chdir = /var/www/flaskapp
module = flaskapp
callable = app
</code></pre>

<p><strong>cat /etc/uwsgi/apps-available/flaskapp2.ini</strong></p>

<pre><code>[uwsgi]
vhost = true
socket = /tmp/flaskapp2.sock
venv = /var/www/flaskapp2/venv
chdir = /var/www/flaskapp2
module = flaskapp2
callable = app
</code></pre>

<p>Both .ini files have been symlinked into <code>/etc/uwsgi/apps-enabled</code>. UWSGI restarts fine without any issues and is up and running. Both flaskapp.sock and flaskapp2.sock are owned by www-data</p>

<p><strong>cat /var/www/flaskapp/flaskapp.py</strong></p>

<pre><code>from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World from flaskapp1!'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
</code></pre>

<p><strong>cat /var/www/flaskapp2/flaskapp2.py</strong></p>

<pre><code>from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World from flaskapp2!'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
</code></pre>

<p><strong>cat /var/www/mydomain.co.uk/index.html</strong></p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;mydomain.co.uk&lt;/h1&gt;

&lt;p&gt;This is the index page of my domain.co.uk&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Both virtual environments have flask installed and will run the flask apps using the development server.</p>

<p>I hope it's something simple that I've missed.</p>