centos6.8配置flask生产环境

来自:互联网
时间:2018-10-02
阅读:

1.测试环境

linode家Centos6.8 64bit镜像

2.安装步骤

1.安装uwsgi容器

https://uwsgi-docs.readthedocs.io/en/latest/

2.安装c环境

yum -y install gcc gcc-c++

3.安装setuptools

wget https://bootstrap.pypa.io/ez_setup.py

sudo python ez_setup.py
4.安装pip

wget https://bootstrap.pypa.io/get-pip.py

sudo python get-pip.py

5.安装python-devel

sudo yum install python-devel

6.安装uwsgi

pip install uwsgi

3.简单helloworld的部署

1.安装flask

pip install flask

2.helloword 程序

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
    return 'Hello World!'
if __name__ == '__mAIn__':
    app.run(host='0.0.0.0')

3.安装Nginx

cd /etc/yum.repos.d/
vi nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
yum install nginx -y

4.修改nginx配置信息

location / { try_files $uri @yourapplication; }
location @yourapplication {
    include uwsgi_params;
    uwsgi_pass unix:/tmp/uwsgi.sock;
}

5.启动

注意 uwsgi和nginx的权限必须统一

假设网站入口文件为app.py

则先启动uwsgi

uwsgi -s /tmp/uwsgi.sock -w app:app --chmod-sock=777

再启动nginx

返回顶部
顶部