needed
flask
pip install flask
uwsgi
pip install uwsgi
nginx
# see
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/
configure files
file tree
~/app1/
├── app1.py
└── uwsgi.ini
/etc/nginx/sites-enabled/
└── app1.conf -> /etc/nginx/sites-available/app1.conf
app1.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
@app.route("/start")
def start():
return "start"
if __name__ == "__main__":
app.run(host='0.0.0.0')
uwsgi.ini
[uwsgi]
module = app1:app
master = true
processes = 3
socket = 127.0.0.1:10001
chmod-socket = 660
vacuum = true
die-on-term = true
uid = www-data
gid = www-data
app1.conf
server{
listen 80;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:10001;
}
}
/etc/nginx/nginx.conf
...
http {
...
include /etc/nginx/sites-enabled/*;
}
run
start nginx
# run nginx test
sudo nginx -t
# for systemd based
sudo systemctl start nginx
start uwsgi
uwsgi --ini ~/app1/uwsgi.ini
當然也可以做成 systemd unit file, 不贅述
result
bare ip address
ip/start
attention
在測試過程中遇到了一個麻煩, uwsgi 老是出現(xiàn)奇怪的錯誤,檢查一番后發(fā)現(xiàn)是由于采用了 pyenv 下 python 環(huán)境所致,重新采用系統(tǒng)的 python 環(huán)境(或通過 virtualenv 構(gòu)建的環(huán)境)即可正常使用.