码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-02-02 11:49:16      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:world   127.0.0.1   turn   编译安装   c++   http   usr   mod   read   

搭建环境

安装依赖包

#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环境搭建——————学习笔记

标签:world   127.0.0.1   turn   编译安装   c++   http   usr   mod   read   

原文地址:http://blog.51cto.com/13523939/2068028

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!