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

来源:互联网 发布:淘宝用的什么web服务器 编辑:程序博客网 时间:2024/05/21 06:42


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 





原创粉丝点击