CentOS7でPython + Flask + uWSGI + Nginxをやってみた1
インストール
以下をインストール。
・Python3.6
・Nginx
・pipでflaskとuwsgiを入れておきます
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
server {
listen 8080;
location / {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
}
Nginxの設定
[uwsgi]
module = app
callable = app
master = true
processes = 1
socket = /tmp/uwsgi.sock
chmod-socket = 666
vacuum = true
die-on-term = true
touch-reload=/path/to/app/reload.trigger
uWSGIリロード
touch /path/reload.trigger
実行
uwsgi --ini app.ini
ブラウザからアクセス
http://[ip address]:8080/
Hello World!が表示されればOK
停止方法
Ctrl + C
または
ps ax|grep uwsgi
kill [プロセスID]
はまったところ
!!! no internal routing support, rebuild with pcre support !!!
以下を追加でインストール
yum install -y pcre-devel
connect() to failed (13: Permission denied) while connecting to upstream
以下の2点が問題でした。
・Nginxの実行ユーザをデフォルトから権限のあるユーザに変更する
# user nginx;
user centos-user;
worker_processes 1;
上記のように/etc/nginx/nginx.confを修正して、nginx再起動する。
sudo systemctl restart nginx
・selinuxが有効になっていた
ディスカッション
コメント一覧
まだ、コメントがありません