Agenda
• Flask Document
•Prepare
• VirtualEnv(Wrapper)
• uWSGI
• nginx
• Tips & Pitfalls
13년 7월 23일 화요일
3.
Flask Documents
• Deployingto a Web Server
• http://flask.pocoo.org/docs/quickstart/#deploying-
to-a-web-server
• Deploying with Distribute
• http://flask.pocoo.org/docs/patterns/distribute/
• Deployment Options
• http://flask.pocoo.org/docs/deploying/
13년 7월 23일 화요일
4.
Prepare
• gcc &python-dev
• sudo apt-get update
• sudo apt-get install build-essential python-dev
python-pip
• Make User (Don’t use ‘root’ user)
• sudo useradd -r -g www-data -s /bin/false uwsgi
• Make dir
• sudo mkdir -p /var/www/myapp
13년 7월 23일 화요일
Tips - Scripts
•start
• sudo /home/myuser/VirtualEnvs/myapp/bin/uwsgi -
x ./uwsgi.xml
• stop
• sudo /home/myuser/VirtualEnvs/myapp/bin/uwsgi --
stop /tmp/myapp.pid
• reload
• sudo /home/myuser/VirtualEnvs/myapp/bin/uwsgi --
reload /tmp/myapp.pid
13년 7월 23일 화요일
15.
Tips - LoggingErrors
• In production, you won’t see log messages
• Send Error Mails!
• Install Mail Server
• sudo apt-get install postfix
ADMINS = ['yourname@example.com']
if not app.debug:
import logging
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler('127.0.0.1',
'server-error@example.com',
ADMINS, 'YourApplication
Failed')
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
13년 7월 23일 화요일
16.
Tips - Configuration
•Best Practice - http://flask.pocoo.org/docs/
config/#configuration-best-practices
• make_config.py
13년 7월 23일 화요일
Pitfall - PassEnvVars
• nginx UWSGI_SETENV not work (Bug!)
• uwsgi_param UWSGI_SETENV
DJANGO_SETTINGS_MODULE=myapp.settings;
• Use uwsgi ‘env’
• <env>MYAPP_DEBUG=False</env>
13년 7월 23일 화요일