Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Forked from hoto17296/app.py
Created April 4, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocodrips/a4d07f0c84db0efb623253fd2d643e1a to your computer and use it in GitHub Desktop.
Save cocodrips/a4d07f0c84db0efb623253fd2d643e1a to your computer and use it in GitHub Desktop.
Nginx + uWSGI + Flask on Amazon Linux
from flask import Flask
application = Flask(__name__)
@application.route("/")
def hello():
return "Hello World!"
# やったことメモ
# もろもろインストール
sudo yum update -y
sudo yum groupinstall "Development Tools"
sudo yum install -y python35-pip python35-devel nginx
# ディレクトリ掘る
sudo mkdir /var/app
sudo chown ec2-user:ec2-user /var/app
cd /var/app
# アプリケーションと uWSGI の設定
vim app.py
sudo pip-3.5 install flask uwsgi
# init.d の設定
vim init.sh
chmod +x init.sh
sudo ln -s /var/app/init.sh /etc/init.d/uwsgi
# Nginx の設定
sudo ln -s /var/app/nginx.conf /etc/nginx/conf.d/uwsgi.conf
sudo vim /etc/nginx/nginx.conf # 実行ユーザを root に変更 & デフォルトサーバを消す
# 自動起動設定
sudo chkconfig uwsgi on
sudo chkconfig nginx on
# サービス起動
sudo service uwsgi start
sudo service nginx start
# 確認
curl localhost
#!/bin/bash
#
# uWSGI
#
# chkconfig: - 58 74
# Source function library.
. /etc/init.d/functions
PATH=$PATH:/usr/local/bin
prog=uwsgi
lockfile=/var/lock/subsys/$prog
app_dir=/var/app
start() {
echo -n $"Starting $prog: "
daemon $prog --socket $app_dir/app.sock --wsgi-file $app_dir/app.py
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
echo -n $"Shutting down $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
server {
location / {
include uwsgi_params;
uwsgi_pass unix:/var/app/app.sock;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment