前段时间自己给部门内部做了一个小网站,主要用于统计一些企业信息。这个项目使用的是Flask框架去做的,这里简单记录一下项目部署的流程,中间可能有遗漏,主要防止自己时间久了忘记。
1.配置虚拟环境
1.1 pip3 install virtualenv
1.2 创建虚拟环境:virtualenv venv
1.3 激活虚拟环境:source venv/bin/activate
1.4 在虚拟环境中安装flask,uwsgi库:pip3 install flask; pip3 install uwsgi
(可能遇到的坑:缺少依赖:yum install -y python3-devel)
1.5 创建配置文件:touch uwsgi.ini
1.6 内容为:[uwsgi]
http = 192.168.126.128:5000
chdir = /home/flask_web
virtualenv =/home/flask_web/venv
wsgi-file = /home/flask_web/app.py
callable = app
#plugins = python
master = true
vacuum = true
chmod-socket = 664
processes = 5
daemonize = /home/flask_web//uwsgi.log
pidfile = /home/flask_web/uwsgi.pid
注:当利用nginx部署:
[uwsgi]
socket = 127.0.0.1:5000
chdir = /home/flask
virtualenv =/home/flask/venv
wsgi-file = /home/flask/app.py
callable = app
#plugins = python
master = true
vacuum = true
chmod-socket = 664
processes = 5
daemonize = /home/flask/uwsgi.log
pidfile = /home/flask/uwsgi.pid
nginx中配置:
server {
listen 80;
server_name 192.168.1.134;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
include /home/application/nginx/conf/uwsgi_params;
uwsgi_pass 0.0.0.0:5000;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
1.7 进入pycharm中Terminal将依赖库版本导出: pip3 freeze > requirements.txt
1.8 在虚拟环境中安装依赖库:pip3 install -r requirements.txt
1.9 启动 uwsgi.ini:uwsgi uwsgi.ini
(可能遇到的坑:ps -ef|grep uwsgi发现没有进程,删掉/home/flask_web/uwsgi/pid 再重新执行一遍 uwsgi uwsgi.ini)
2.0 将项目copy到/home/flask_web目录下,并将.py文件赋权
2.1 启动uwsgi.ini
2.2 ps -ef|grep uwsgi 查看进程是否启动
2.3 重启uwsgi: uwsgi --reload uwsgi.pid
2.4 停止: uwsgi --stop uwsgi.pid
2.5 启动: uwsgi --ini uwsgi.ini
原文:https://www.cnblogs.com/oyaisusu/p/13817081.html