centos+nginx+uwsgi+Python3+flask操作步骤

论坛 期权论坛 脚本     
匿名技术用户   2021-1-6 05:26   18   0


1、下载Python3
$ wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
2、安装openssl
$ yum install openssl -y (-y 是遇到选择yes/no的时候默认提前yes了)
$ yum install openssl-devel -y
3、解压Python3
$ tar -zxf Python-3.6.3.tgz
$ cd Python-3.6.3
4、编译Python
$ ./configure
$ make & make install
5、安装虚拟环境
$ pip3 install virtualenv
$ virtualenv --no-site-packages -p python3 **_env (不关联系统库,使用python3)


$ source **_env/bin/activate(激活)
$ deactivate (退出虚拟环境)
6、安装nginx
$ yum install nginx
$ service nginx start
6.1、谁占用了80端口?kill掉
$ netstat -tln | grep 80
$ kill -9 'id'
7、安装uwsgi
$ pip install uwsgi
8、配置nginx与uwsgi之间
$ vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_param UWSGI_PYHOME /var/www/leefeng_env;
uwsgi_param UWSGI_CHDIR /var/www/leefeng;
uwsgi_param UWSGI_SCRIPT core:app;
}
}
$ vim /var/www/leefeng/uwsgi.ini
[uwsgi]
socket = 127.0.0.1:8000
plugins = python
chidir = /var/www/leefeng
virtualenv = /var/www/leefeng_env
wsgi-file = core.py
callable = app


threads = 2
processes = 4
$ pip install flask
$ vim /var/www/leefeng/core.py
from flask import Flask
app=Flask(__name__)


@app.route('/')
def index():
return '<h2>Hello Word!</h2>'


if __name__ == '__main__':
app.run()
$ uwsgi uwsgi.ini




make时报错zipimport.ZipImportError: can't decompress data; zlib not available:#yum install zlib-devel
启动nginx报错:nginx: [emerg] socket() [::]:80 failed=需要在nginx.conf 注释掉#listen [::]:80 default_server;
pip报错:ssl module in Python is not available=(需要重新python :./configure make & make install )
yum install openssl -y (-y 是遇到选择yes/no的时候默认提前yes了)
yum install openssl-devel -y





分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP