nginx+uwsgi+python3.6+virtualenv+flask环境搭建

tags
python
type
Post
date
Oct 1, 2019
status
Published
安装python 3.6.2
去官网下载编译安装包或者直接执行以下命令下载
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
解压
tar -xvJf Python-3.6.2.tar.xz
切换进入
cd Python-3.6.2
编译安装
sehll
./configure prefix=/usr/local/python3
make && make install
安装完毕,/usr/local/目录下就会有python3了
因此我们可以添加软链到执行目录下/usr/bin
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
安装 python虚拟环境及flask,uwsgi
安装virtualenv
sudo pip install virtualenv
建立网站目录
mkdir python
在目录下建立python3虚拟环境
virtualenv -p /usr/local/python3/bin/python3 env2
启动虚拟环境
source env2/bin/activate
安装flask 和 uwsgi
pip install flask
pip install uwsgi
编写python flask 脚本
python
配置uwsgi
ini
[uwsgi]
chdir=/var/www/html/python
home=/var/www/html/python/env2
module=manage
callable=app
processes=2
master=true
chmod-socket=666
logfile-chmod=644
daemonize=%(chdir)/uwsgi.log
socket=%(chdir)/table.sock
配置nginx
在vhost 目录下新建 table.jqpress.com.conf,配置如下
server {
listen 80;
server_name www.mysite.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/python/table.sock;
}
}
启动和关闭
启动 uwsgi
uwsgi --ini uwsgi.ini
关闭 uwsgi(比较暴力)
killall -9 uwsgi
nginx 启动命令:
sudo /usr/local/nginx/sbin/nginx
nginx 重启命令:
sudo /usr/local/nginx/sbin/nginx -s reload
测试成功显示
浏览器打印出以下信息
Hello World! flask run success
Python 3.6.2 (default, Sep 24 2017, 21:30:53) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

© robotbird 2023