NGINX Unit

Flask Apps§

To run your Flask apps in Unit:

  1. Install Unit with the appropriate Python language module version.

  2. If you haven’t already done so, create your Flask app.

  3. Prepare Unit configuration for your update. To obtain an initial template, query the control API:

    # curl --unix-socket /path/to/control.unit.sock \
           http://localhost/config/ > config.json
    

    Note

    Control socket path may vary; run unitd --help or see Startup for details.

    This creates a JSON file with Unit’s current settings. Edit the file, adding a listener entry to point to a Unit app that references your application’s WSGI module as module and virtual environment as home:

    {
        "listeners": {
            "*:8080": {
                "pass": "applications/flask_app"
            }
        },
    
        "applications": {
            "flask_app": {
                "type": "python 3",
                "path": "/home/flask/flask_app/",
                "home": "/home/flask/venv/",
                "module": "wsgi"
            }
        }
    }
    

    Note

    Mind that Unit will look for an application callable in the WSGI module to run the app.

    For details, see Python app settings.

  4. Upload the updated configuration:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
    

    After a successful update, your app should be available on the listener’s IP address and port:

    $ curl http://127.0.0.1:8080/