- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2019-01-08T09:46:56+00:00","","")
#author("2019-01-11T06:28:39+00:00","","")
* Nginx+uwsgiでFlaskアプリケーション [#jfbc4dba]
#setlinebreak(on)
#contents
-- 関連
--- [[Nginx]]
--- [[Flaskの基礎]]
-- 参考
--- https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
#TODO
** 概要 [#gdd7ab34]
#html(<div style="padding-left:10px">)
#TODO
#html(</div>)
** Flask、uWSGI インストール [#occabcae]
#html(<div style="padding-left:10px">)
#myterm2(){{
mkdir test_flask && cd test_flask
python3 -m venv .venv
source .venv/bin/activate
pip install flask
pip install uwsgi
}}
#html(</div>)
** サンプルアプリケーション [#q7453491]
#html(<div style="padding-left:10px">)
app.py
#mycode2(){{
from flask import Flask
import datetime
app = Flask(__name__)
@app.route('/')
def index():
now = datetime.datetime.now().strftime('%H:%M:%S.%f')
return f'<h1>top page!({now})</h1>\n'
@app.route('/sample')
def sample():
now = datetime.datetime.now().strftime('%H:%M:%S.%f')
return f'<h1>sample page!({now})</h1>\n'
}}
#html(</div>)
** まずは uwsgiのみで動かしてみる [#v450df85]
#html(<div style="padding-left:10px">)
参考
https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
uwsgi起動
#myterm2(){{
uwsgi --http :3031 --wsgi-file app.py --callable app
}}
確認
#myterm2(){{
curl http://localhost:3031/
top page!(13:35:03.767707)
}}
#html(</div>)
** nginxインストール [#r1784e69]
#html(<div style="padding-left:10px">)
[[Nginx]] を参照
#html(</div>)
** nginxの設定 [#zb01b5b3]
#html(<div style="padding-left:10px">)
#TODO
#html(</div>)
** 全部入りのDockerイメージを作る [#lee978eb]
#html(<div style="padding-left:10px">)
#myterm2(){{
apt-get -y install software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt-get update
apt-get -y install python3.6
}}
#html(</div>)
** 全部入りのDockerイメージを作る [#lee978eb]
#html(<div style="padding-left:10px">)
Dockerfile
#mycode2(){{
FROM ubuntu
apt-get update
apt-get -y install software-properties-common
add-apt-repository -y ppa:jonathonf/python-3.6
apt-get update
apt-get -y install python3.6
apt-get -y install nginx
ln -s /usr/bin/python3.6 /usr/bin/python
rm -rf /usr/bin/python3
ln -s /usr/bin/python3.6 /usr/bin/python3
}}
#html(</div>)