flask|Nginx+uwsgi+flask部署实战

环境:
操作系统:centos 7
python版本: V3.6
python框架: flask
nginx版本:1.10.1
flask应用的安装步骤请查看上一篇博客:https://blog.csdn.net/u011089760/article/details/90174285
1).nginx的安装
【flask|Nginx+uwsgi+flask部署实战】1.gcc安装
gcc是对源码进行编译的插件,如果没有按照需要执行:
yum install gcc-c++
2.PCRE pcre-devel 安装
yum install -y pcre pcre-devel
3.zlib 安装
yum install -y zlib zlib-devel
4.下载nginx源文件
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
解压源文件:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

5.编译源文件
./configure
6.编译安装
make
make install
7.启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
8.查询nginx进程
ps aux|grep nginx
9.开启端口80端口
firewall-cmd --zone=public --add-port=80/tcp –premanent
10.访问测试
http://192.168.13.160/
flask|Nginx+uwsgi+flask部署实战
文章图片

至此nginx安装成功
2).修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf#红色部分为修改内容
upstream flask{
server 127.0.0.1:8001;
}
server {
listen80;
server_namelocalhost;
#charset koi8-r;
#access_lo
location / {
include uwsgi_params;
uwsgi_pass flask;
}
}
重启nginx:
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

3).配置uwsgi启动flask
编辑配置文件vim /home/pythonfile/uwsgi.ini
[uwsgi]
http=:5000
socket = 127.0.0.1:8001
wsgi-file=/home/pythonfile/flask_helloworld.py
callable=app
processes=4
threads=2
stats = 127.0.0.1:9191
vacuum = true
uwsgi启动flask: uwsgi /home/pythonfile/uwsgi.ini
flask|Nginx+uwsgi+flask部署实战
文章图片

4).访问测试
flask|Nginx+uwsgi+flask部署实战
文章图片

    推荐阅读