3

I am trying to deploy a simple web app that I have built using Python and Flask.

My app has the following structure:

/var/www/watchgallery/ + app + __init__.py + views.py + templates + flask #virtual environment for Flask + run.py #script I used in my machine to start the development Flask server + watchgallery_nginx.conf + watchgallery_uwsgi.ini + watchgallery_uwsgi.sock 

For this purpose of deploying, I am following this link: http://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/

In this tutorial, the Flask app consists of only a hello.py file. The way he configures his uwsgi file is like this (/var/www/demoapp/demoapp_uwsgi.ini):

[uwsgi] #application's base folder base = /var/www/demoapp #python module to import app = hello module = %(app) home = %(base)/venv pythonpath = %(base) #socket file's location socket = /var/www/demoapp/%n.sock #permissions for the socket file chmod-socket = 666 #the variable that holds a flask application inside the module imported at line #6 callable = app #location of log files logto = /var/log/uwsgi/%n.log 

I have tried to apply the same logic to my uwsgi.ini file, but I am doing something wrong. This is how my file looks like:

[uwsgi] #application's base folder base = /var/www/watchgallery #python module to import app = run module = %(app) home = %(base)/flask pythonpath = %(base) #socket file's location socket = /var/www/watchgallery/%n.sock #permissions for the socket file chmod-socket = 666 #the variable that holds a flask application inside the module imported at line #6 callable = app 

When I am developing my app in my local machine, I run this command to start de the server: ./run.py.

This is my run.py file:

#!flask/bin/python from app import app app.run(debug = False) 

Now, my question is: how should my uwsgi.ini file look like given that my Flask app consists of more than a single file?

1 Answer 1

4

It doesn't matter how complex your application is. You tell uWSGI where the entry is, the rest is processed normally with Python imports.

In your case the entry is module = %(app) and callable = app. So uWSGI will load the module and send requests to the callable which is a Flask application.

Now since the requests are to be served by uWSGI and not Flask's server, you don't need the app.run(debug = False) line. But you can keep development and production code the same with this trick:

#!flask/bin/python from app import app if __name__ == "__main__": app.run(debug = False) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.