Flask mit nginx und uWSGI bereitstellen
Installieren:
nginx
python-virtualenv
build-essential
python-dev
python
sudo apt-get install python-virtualenv build-essential python python-devsudo mkdir /var/www/demoapp
cd /var/www/demoapp
virtualenv venv
. venv/bin/activateflask installieren:
pip install flaskuwsgi installieren:
pip install uwsginginx config:
server {
listen 80; #443
server_name myapp.com;
charset utf-8;
client_max_body_size 75M;
location / { try_files $uri @myapp; }
location @myapp {
include uwsgi_params;
uwsgi_pass unix:/var/www/demoapp/demoapp_uwsgi.sock;
}
#alternnative locatio
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/demoapp/demoapp_uwsgi.sock;
}
}nginx -t
service nginx reloaduWSGI config:
/var/www/demoapp/demoapp_uwsgi.ini:
[uwsgi]
#application's base folder
base = /var/www/demoapp
#python module to import, start/setup file
app = myapp
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
# security
#chmod-socket = 644
#the variable that holds a flask application inside the module
callable = app
#location of log files
logto = /var/log/uwsgi/%n.loguWSGI Emperor
/etc/init/uwsgi.conf
description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]
respawn
env UWSGI=/var/www/demoapp/venv/bin/uwsgi
env LOGTO=/var/log/uwsgi/emperor.log
exec $UWSGI --master --emperor /etc/uwsgi/vassals --die-on-term --uid www-data --gid www-data --logto $LOGTOconfig dateien nach vassals verlinken –> /etc/uwsgi/vassals
sudo mkdir /etc/uwsgi && sudo mkdir /etc/uwsgi/vassals
sudo ln -s /var/www/demoapp/demoapp_uwsgi.ini /etc/uwsgi/vassalsuWSGI starten:
sudo start uwsgiStatische Dateien:
location /static {
root /var/www/demoapp/;
}https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/