CentOS 7.5安装python3.7 uwsgi

@TOC

环境

  • CentOS 7.5 x64

在这里插入图片描述

安装python3.7.3

准备编译环境

yum install gcc openssl-devel bzip2-devel  libffi-devel -y

下载官方源码

cd /usr/src
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar xzf Python-3.7.3.tgz

编译安装

cd Python-3.7.3
./configure --enable-optimizations
make altinstall
# 默认安装到 /user/local/bin/ 下面
# 验证Python版本
python3.7 -V
# 安装完毕后自带pip3
pip3.7 -V

在这里插入图片描述

安装uwsgi并配置Nginx

安装uwsgi

pip3.7 install uwsgi

uwsgi配置

uwsgi.ini

[uwsgi]
socket = 127.0.0.1:9090
set-placeholder = BASE_DIR=/usr/share/nginx
chdir = %(BASE_DIR)
wsgi-file = %(BASE_DIR)/wsgi.py
touch_reload = %(BASE_DIR)/wsgi.py
daemonize = %(BASE_DIR)/uwsgi.log
pidfile = %(BASE_DIR)/uwsgi.pid

测试wsgi.py

# coding=utf-8
# pip3.7 install flask
# wsgi.py

from flask import Flask, request


app = Flask(__name__)

@app.route('/')
def index():
	_hreaders_list = map(lambda x: '%s: %s' % (x, request.headers[x]), request.headers.keys())
	ret = '

' + '

'.join(_hreaders_list) + '

'
+ u'

请求的URL: %s

'
% request.url return ret application = app

启动uwsgi

uwsgi --ini uwsgi.ini

nginx 配置

server {
        listen 80;
        location / {
                uwsgi_pass 127.0.0.1:9090;
                include uwsgi_params;
        }
}

结果

CentOS 7.5安装python3.7 uwsgi_第1张图片

自动启动

chmod a+x /etc/rc.d/rc.local
# 在/etc/rc.d/rc.local添加一行
# uwsgi --ini /root/uwsgi.ini

你可能感兴趣的:(Web服务器)