title: Run Python Flask application with nginx Unit
body: <p>I played around today with the nginx Unit application server and Python 3. It works fine as long as I run a simple WSGI application, but I won't work (404) when trying to use Flask...</p>
  
  <p>nginx config:</p>
  
  <pre><code>upstream unit_backend {
      server 127.0.0.1:8300;
  }
  
  server {
      listen 80 default_server;
      listen [::]:80 default_server;
  
      root /var/www/html;
  
      server_name _;
  
      location / {
  
      }
  
      location /unittest {
              proxy_pass http://unit_backend;
              proxy_set_header Host $host;
      }
  }
  </code></pre>
  
  <p>Unit config:</p>
  
  <pre><code>{
  "listeners": {
      "*:8300": {
          "application": "test"
      }
  },
  
  "applications": {
      "test": {
          "type": "python 3.5",
          "processes": 4,
          "user": "noisefloor",
          "group": "noisefloor",
          "path": "/home/noisefloor/code/unit_test",
          "module": "wsgi"
      }
  },
  
  "access_log": "/var/log/access.log"
  }
  </code></pre>
  
  <p>wsgi.py which works when opening <a href="http://127.0.0.1/unittest" rel="nofollow noreferrer">http://127.0.0.1/unittest</a> in the browser:</p>
  
  <pre><code>from datetime import datetime
  
  def application(environ, start_response):
      status = '200 OK'
      headers = [('Content-type', 'text/plain; charset=utf-8')]
      start_response(status, headers)
      text = 'Hello World @ {}'.format(datetime.now())
      return [text.encode('utf-8')]
  </code></pre>
  
  <p>When the wsgi.py is as follows:</p>
  
  <pre><code>from flask import Flask
  
      application = Flask(__name__)
  
      @application.route('/')
      def test():
          return 'Hello Flask!'
  </code></pre>
  
  <p>It get the 404, but I see what I expect to see when calling <a href="http://127.0.0.1:8300" rel="nofollow noreferrer">http://127.0.0.1:8300</a> - so it basically work, it just don't get why it won't work when calling <a href="http://127.0.0.1/unittest" rel="nofollow noreferrer">http://127.0.0.1/unittest</a></p>