杂谈部署

Flask + Gunicorn + Nginx 部署

nginx 位置
vim /etc/nginx/nginx.conf
/usr/local/openresty/nginx/sbin/nginx

vim
i 插入
esc :w 保存 :q退出

supervisor命令
supervisorctl
service supervisor restart

切换python2 python3

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

然后再输入:

sudo update-alternatives --config python

nginx -s reload
查看端口占用

lsof -i:80

强制覆盖本地

git fetch --all  
git reset --hard origin/master 
git pull
#!/usr/bin/env python3
import sys
# 设置当前目录为工作目录

from os.path import abspath
from os.path import dirname

sys.path.insert(0, abspath(dirname(__file__)))




# 引入 app.py
import app

# 必须有一个叫做 application 的变量
# gunicorn 就要这个变量
# 这个变量的值必须是 Flask 实例
# 这是规定的套路(协议)
application = app


# -*- coding: utf-8 -*-
import os

from manage import app
import datetime

# Create an application instance that web servers can use. We store it as
# "application" (the wsgi default) and also the much shorter and convenient
# "app".
application = app

@app.context_processor
def template_extras():
    """
    上下文处理装饰器,返回的字典的键可以在上下文中使用
    :return:
    """
    return {'enumerate': enumerate, 'len': len, 'datetime': datetime}

# 这是把代码部署到 apache gunicorn nginx 后面的套路
"""
➜  ~ cat /etc/supervisor/conf.d/python101.conf

[program:test]
command=/usr/local/bin/gunicorn wsgi --bind 0.0.0.0:80 --pid /tmp/todo.pid
directory=/root/tmp/test
autostart=true
"""/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:81 manage:app
from manage import db
db.create_all()
python manage.py db

./venv/bin/gunicorn -w 4 -b 127.0.0.1:8080 manager:app



gunicorn --worker=3 manage:manager -b 0.0.0.0:8000

gunicorn -b 127.0.0.1:8000 -k gevent -w 1 manager.wsgi

gunicorn wsgi --bind 0.0.0.0:8000
gunicorn -b 127.0.0.1:8000 -k gevent -w 1 wsgi

[program:python101]
command=/usr/local/bin/gunicorn wsgi --bind 0.0.0.0:8000
directory=/var/www/python101
autostart=true
nano /etc/supervisor/conf.d/python101.conf

vim /etc/supervisor/conf.d/bbs.conf
vim /etc/supervisor/conf.d/python101.conf

[program:python101]
command=/usr/local/bin/gunicorn wsgi --bind 0.0.0.0:8000 --pid /tmp/python101.pid
directory=/root/var/www/python101
autostart=true
autorestart=true



supervisorctl
service supervisor restart 

 cat /etc/nginx/sites-enabled/chat
 vim /etc/nginx/sites-enabled/python101
 rm /etc/nginx/sites-enabled/python101

 service nginx restart

 cat /etc/nginx/sites-enabled/python101
 cat /etc/nginx/nginx.conf
 vim /etc/nginx/sites-enabled/chat
 vim /etc/supervisor/conf.d/python101.conf

你可能感兴趣的:(杂谈部署)