centos+python2+flask+nginx+uwsgi环境搭建
Posted NAVYSUMMER
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos+python2+flask+nginx+uwsgi环境搭建相关的知识,希望对你有一定的参考价值。
环境:
1.centos7
2.python2
3.flask1.1.2
4.nginx
1.安装python虚拟环境
pip install virtualenv
2.创建虚拟环境
mkdir flask_project cd flask_project virtualenv venv
3.在虚拟环境里安装flask
source source venv/bin/activate pip install flask
4.创建flask项目
vim myapp.py
from flask import Flask app = Flask(__name__) @app.route(\'/\') def index(): return "I am a flask example!"
5.安装nginx
yum install nginx -y
6.全局安装或者虚拟环境uwsgi
pip install uwsgi
7.编写uwsgi文件
[uwsgi] #socket = 127.0.0.1:3031 socket = /run/mysite.sock chdir = /opt/flask_project wsgi-file = myapp.py callable = app #http = 127.0.0.1:9191 virtualenv = /opt/flask_project/venv daemonize = /var/log/uwsgi.log processes = 4 uid = root gid = root
8.编写并导入nginx配置文件
vim /etc/nginx/vhost/flask.conf
server { listen 8000 default_server; listen [::]:8000 default_server; server_name localhostA; include /etc/nginx/default.d/*.conf; index index.html index.htm; location / { include uwsgi_params; uwsgi_pass unix:///run/mysite.sock; } }
在/etc/nginx/nginx.conf里添加以下内容
include /etc/nginx/vhost/*.conf;
9.启动uwsgi和重启nginx
10.项目详情:
include /etc/nginx/vhost/*.conf;
以上是关于centos+python2+flask+nginx+uwsgi环境搭建的主要内容,如果未能解决你的问题,请参考以下文章
centos+python2+apache2+flask环境搭建
centos+python2+apache2+flask环境搭建
centos6.5+python2.7+flask+apache+mod-wsgi部署
centos 7 nginx+uwsgi+flask 环境搭建