NGINX+UWSGI+PYTHON+FLASK环境搭建——————学习笔记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NGINX+UWSGI+PYTHON+FLASK环境搭建——————学习笔记相关的知识,希望对你有一定的参考价值。
搭建环境
安装依赖包
#
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=app
processes=2
threads=2
buffer-size=65536
修改配置文件
#vim /usr/local/nginx/conf/nginx.conf<br/>
server {<br/>
listen 80;<br/>
server_name www.mdzzzz.cn;<br/>
location / {<br/>
include uwsgi_params;<br/>
uwsgi_pass 127.0.0.1:5000;<br/>
}<br/>
}`
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环境搭建——————学习笔记的主要内容,如果未能解决你的问题,请参考以下文章
NGINX+UWSGI+PYTHON+FLASK环境搭建——————学习笔记
Python3 - Nginx+uwsgi+Flask 部署到Centos服务器