您的位置:首页 > 运维架构 > Nginx

NGINX+UWSGI+PYTHON+FLASK环境搭建——————学习笔记

2018-02-02 10:41 381 查看

搭建环境

安装依赖包

#
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[/code] 

安装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__)
return 'helloword'[/code]
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


浏览器测试

[url=http://www.mdzzzz,cn/helloworld/]http://www.mdzzzz,cn/helloworld/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息