简体   繁体   中英

unable to load configuration from uwsgi when attempting to run flask app via uwsg

I've the following uwsgi app.ini file:

[uwsgi]
wsgi-file = wsgi.py
callable = app
socket = :5000
processes = 5
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

wsgi.py content:

from app import start

start()

and finally app.py which is the Flask app itself (pretty long so I'll only put the relevant):

# instantiate the app
app = Flask(__name__, static_url_path='', static_folder='static', template_folder='templates')
app.config.from_object(__name__)

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})


@app.route('/')
def index():
    return render_template('index.html')


... all sort of methods here ...


def start():
    print("STARTING !!!")
    app.run(host='0.0.0.0')


if __name__ == '__main__':
    start()

all files are in the same folder. when I'm running uwsgi app.ini I'm getting this:

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
unable to load configuration from uwsgi

why is this?

Thanks for any help

A quick look shows two problems. First, uwsgi and app.run() aren't compatible. You use the latter when you're using the Flask development environment. uwsgi wants the object that holds the Flask instance. By convention, that's app , though you can use a different name (and configure uwsgi to look for a different name).

And that's the second issue. uwsgi has loaded wsgi.py (causing the app.run() that's getting you the most of what you're seeing. Then it's looking for app . But because you're importing from app , the app that wsgi.py has isn't the Flask instance.

The simple thing to do would be (in uwsgi.ini) to replace

file=wsgi.py

with

module=app:app

That should bypass the call to start() , letting uwsgi handle things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM