기본 콘텐츠로 건너뛰기

ubuntu, flask restful

ubuntu, flask restful

$ cd /home/service

$ git clone https://gyunseul9@bitbucket.org/gyunseul9/api_flask.git

$ virtualenv api_flask

$ cd api_flask

$ . bin/activate

$ pip3 install flask

$ pip3 install flask-restful

$ pip3 install uwsgi

$ pip3 freeze > requirements.txt

$ vi api.py

---

from flask import Flask

from flask_restful import Resource, Api

app = Flask(__name__)

api = Api(app)

class CreateUser(Resource):

def post(self):

return {'status':'success'}

api.add_resource(CreateUser,'/user')

if __name__ == '__main__':

app.run('0.0.0.0',debug=True)

---

$ python3 api.py

$ git add .

$ git commit -am "google, initialize api_flask"

$ git push

$ mkdir env

$ vi ./env/uwsgi_api.ini

---

[uwsgi]

chdir=/home/service/api_flask

chmod-socket=666

callable=app

module=api

socket=/tmp/uwsgi_api.sock

virtualenv=/home/service/api_flask

master=true

processes=5

max-requests=1000

harakiri=10

lazy-apps=true

logto=/var/log/uwsgi/uwsgi_api.log

enable-threads = true

---

$ vi run.sh

---

#!/bin/bash

source /home/service/api_flask/bin/activate

uwsgi --ini /home/service/api_flask/env/uwsgi_api.ini

---

$ chmod +x run.sh

$ vi /etc/nginx/sites-available/default

---

server {

listen 8080;

server_name 0.0.0.0;

location / {

try_files $uri @api;

}

location @api {

include uwsgi_params;

uwsgi_pass unix:/tmp/uwsgi_api.sock;

}

}

---

$ vi /etc/supervisor/conf.d/api.conf

---

[program:api]

command=/home/service/api_flask/run.sh

environment=HOME='/home/service',USER='service'

directory=/home/service/api_flask

autostart=true

autorestart=true

startretries=3

---

$ service nginx restart

$ cd /tmp

$ /home/service/api_flask/run.sh

ctrl + c

$ ls -al

$ service supervisor stop

$ service supervisor start

$ supervisorctl

공유하기 글 요소 저작자표시

from http://lonbehold.tistory.com/132 by ccl(A) rewrite - 2020-03-07 00:20:37

댓글

이 블로그의 인기 게시물

Flask 13. pythonanywhere에 배포하기

Flask 13. pythonanywhere에 배포하기 Login: PythonAnywhere It's always a pleasure to hear from you! Ask us a question, or tell us what you love or hate about PythonAnywhere. We'll get back to you over email ASAP. Sorry, there was an error connecting to the server. Please try again in a few moments... www.pythonanywhere.com from http://ohdowon064.tistory.com/124 by ccl(A) rewrite - 2020-03-11 15:54:10

[ubuntu] FLASK_APP

[ubuntu] FLASK_APP Development/Debugging 🐞 FLASK_ENV=development FLASK_APP = app.py flask run zsh: command not found: FLASK_APP ✔️ FLASK_ENV=development FLASK_APP=app.py flask run 띄어쓰기를 해서 저런 오류를 출력할수도 있구나 😲 참고 : 108p에서 FLASK가 FKAS로 오타나있다. from http://hee-stories.tistory.com/18 by ccl(A) rewrite - 2020-03-24 17:20:11