-
-
Save cocodrips/a4d07f0c84db0efb623253fd2d643e1a to your computer and use it in GitHub Desktop.
Nginx + uWSGI + Flask on Amazon Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
application = Flask(__name__) | |
@application.route("/") | |
def hello(): | |
return "Hello World!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# やったことメモ | |
# もろもろインストール | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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