搭建环境
安装依赖包
#
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel GroOP gd libXpm livxslt sqlite-devel
安装 nginx
#yum -y install nginx
启动 nginx
#systemctl start nginx
测试 nginx
#ps -ef |grep nginx
下载 python3.6 压缩包
#wget -c https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
安装 python3.6
#tar -xvf Python-3.6.0.tgz
#cd Python-3.6.0
#./congigure --prefix=/usr/local/python3.6 && make && make install
做 python3.6 的链接
#ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
修改环境变量:
#vim ~/.bash_profile
PATH=$PATH:%HOME/bin:/usr/local/python3.6/bin
测试 python3.6
python -V
Python 3.6.4
使用 pip 安装 python 模块
必须使用 pip3, 编译安装的 python3.6 自带 pip3
#rm -rf /usr/bin/pip
#ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip
安装 flask
#pip install flask
创建项目目录
#mkdir /root/flask_pro
创建入口文件
#vim /root/flask_pro/flask_app.py
from flask import Flask,request
app = Flask(__name__)
br/>`@app.route('/helloworld/')` def helloword() return 'helloword' if __name__ == '_main_' : app.run(host='0.0.0.0',port=5000)
运行 flask app #python flask_app.py 安装 uwsgi: pip install uwsgi 配置 uwsgi: vim /root/flask_pro/uwsgi.ini [uwsgi] socket=127.0.01:5000 chdir=/root/flask_pro/ wsgi-file=flask_app.py callable=appprocesses=2threads=2buffer-size=65536 修改配置文件 #vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.mdzzzz.cn;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1 : 5000;
}
}` python 加载 uwsgi.ini #uwsgi -d --ini /root/flask_pro/uwsgi.ini 做开机启动 #vim /etc/rc.local uwsgi -d --ini /root/flask_pro/uwsgi.ini #chmod +x /etc/rc.d/rc.local #systemctl enable rc-local 重启 nginx #systemctl restart nginx 浏览器测试
http://www.mdzzzz,cn/helloworld/
NGINX+UWSGI+PYTHON+FLASK 环境搭建 ------ 学习笔记
来源: http://www.bubuko.com/infodetail-2484212.html