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

centos+python2+flask+nginx+uwsgi环境搭建

时间:2020-05-12 11:50:14      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:process   bash   source   ret   img   wsgi   pass   vhost   amp   

环境:

       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环境搭建

标签:process   bash   source   ret   img   wsgi   pass   vhost   amp   

原文地址:https://www.cnblogs.com/navysummer/p/12874814.html

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