$ sudo pacman -S nginx python2 python2-pip
$ sudo pip2 install Flask uwsgi
hello/
__init__.py
templates/
index.html
__init__.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
templates/index.html
<!DOCTYPE html>
<h1>Hello, world!</h1>
uwsgiソケットを使う方法
server {
listen 80;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
}
}
$ uwsgi -s 127.0.0.1:5000 -w hello:app
httpプロクシを使う方法
$ uwsgi --http 127.0.0.1:5000 -w hello:app
server {
listen 80;
server_name localhost;
location / {
include uwsgi_params;
proxy_pass http://127.0.0.1:5000;
}
}
Arch Linux
/lib/systemd/system/helloapp.service
[Unit]
Description=Hello Application
Wants=nginx.service
Before=nginx.service
[Service]
ExecStart=/usr/bin/uwsgi -s :5000 --chdir /opt/webapp -w hello:app --pidfile /tmp/helloapp.pid
ExecReload=/usr/bin/uwsgi --reload /tmp/helloapp.pid
ExecStop=/usr/bin/uwsgi --stop /tmp/helloapp.pid
[Install]
WantedBy=multi-user.target
$ sudo systemctl enable helloapp.service
$ sudo systemctl start helloapp
$ sudo systemctl reload helloapp
$ sudo systemctl stop helloapp