Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

安装虚拟环境

安装虚拟环境

pip2 install virtualenvwrapper
# **查找安装路径**   
which virtualenvwrapper.sh

virtual

编辑.bashrc

vim ~/.bashrc
# 增加以下环境变量
export WORKON_HOME=$HOME/.virtualenvs  
source /usr/local/bin/virtualenvwrapper.sh

立即生效

source .bashrc

查找python3路径

which python3

python3

创建虚拟环境

mkvirtualenv --python=/usr/bin/python3 name-env

workon name-env

切换/激活 虚拟环境

workon name-evn

cd ~/.virtualenvs/name-env/bin/

退出虚拟环境

deactivate name-env

安装git用来传代码

安装git

yum install git
# 生成公钥
ssh-keygen -t rsa -C “email”
# 查看公钥
cat ~/.ssh/id_rsa.pub

#同步代码
git clone  

Uwsgi

pip3 install uwsgi

在项目中创建uwsgi.ini配置文件

  [uwsgi]

  # 必须全部为绝对路径
  # 项目的路径
  chdir = /root/flask_f/
  # Django的wsgi文件
  wsgi-file = /root/flask_f/app.py
  # 回调的app对象
  callable = app
  # Python虚拟环境的路径
  home = /root/.virtualenvs/small-env

  # 进程相关的设置
  # 主进程
  master = true
  # 最大数量的工作进程
  processes = 10

  # nginx 直接用socket
  #http            = :80
  socket = /root/flask_f/small.sock

  # 设置socket的权限
  chmod-socket = 666
  # 退出的时候是否清理环境
  vacuum = true

启动应用服务器 指定项目的uwsgi.ini配置文件

uwsgi --ini uwsgi.ini

Nginx

Nginx 配置,目录下增加自定义配置文件

cd /etc/nginx/conf.d
upstream small{

    server unix:///root/flask_f/small.sock;
}

# 配置服务器
server {
    # 监听的端口号
    listen      80;
    # 域名
    server_name 47.111.249.148;
    charset     utf-8;

    # 最大的文件上传尺寸
    client_max_body_size 75M;  

    # 静态文件访问的url
    location /static {
        # 静态文件地址
        alias /root/flask_f/static;
    }

    # 最后,发送所有非静态文件请求到django服务器
    location / {
        uwsgi_pass  small;
        # uwsgi_params文件地址
        include     /etc/nginx/uwsgi_params;
    }
}