美文网首页
Centos部署Flask

Centos部署Flask

作者: royluck | 来源:发表于2020-06-08 10:25 被阅读0次
参考:如何在 CentOS 上部署 Flask
参考笔记:https://share.weiyun.com/xwxOBe19

镜像 目路结构
pipenv shell
pipenv run pip freeze>requirements.txt
将requirements.txt上传至服务器根目录test
source .env/bin/activate
pip3 install -r requirements.txt 
deactivate 
uwsgi --ini uwsgi.ini

python项目结合pipenv创建requirements.txt实现快速安装依赖包

uwsgi.ini配置:
[uwsgi]
chdir=/www/wwwroot/test/govtool_api # 工程目录
home=/www/wwwroot/test/.env # 虚拟环境目录
module=go # 启动flask应用的文件名,不用加.py
callable=app # 应用名,与我们hell
master=true
processes=2 # worker的进程个数
chmod-socket=666
logfile-chmod=644
procname-prefix-spaced=test # uwsgi的进程名称前缀,启动后可通过ps -ef | grep test查找到这个进程
py-autoreload=1 #py文件修改,自动加载,也就是设置热启动了
#http=0.0.0.0:8080 #监听端口,测试时使用

vacuum=true  # 退出uwsgi是否清理中间文件,包含pid、sock和status文件
#注意这里的文件路径!!!
socket=%(chdir)/uwsgi/uwsgi.sock # socket文件,配置nginx时候使用
stats=%(chdir)/uwsgi/uwsgi.status # status文件,可以查看uwsgi的运行状态
pidfile=%(chdir)/uwsgi/uwsgi.pid # pid文件,通过该文件可以控制uwsgi的重启和停止
daemonize=%(chdir)/uwsgi/uwsgi.log # 设置后台模式,然后将日志输出到uwsgi.log。当调试时,可先注释掉此内容
image.png
常用命令:
uwsgi --ini uwsgi.ini             # 启动
uwsgi --reload uwsgi.pid          # 重启
uwsgi --stop uwsgi.pid            # 关闭
#服务器nginx配置
server
{
    listen 80;
    listen 5657;
    server_name www.test.com 47.**.***.**4;  # 公网ip
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.test.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    #include enable-php-56.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/www.test.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
    
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/www/wwwroot/test/govtool_api/uwsgi/uwsgi.sock;
    }

    location ~ /static/ {
            #root后面写项目static文件夹在你后台的绝对路径
            root /www/wwwroot/test;
    }
    
    access_log  /www/wwwlogs/www.test.com.log;
    error_log  /www/wwwlogs/www.test.com.error.log;
}
#前端静态页面
server
{
    listen 80;
    listen 5656;
    server_name www.moqianfu.com  47.**.***.**4;  # 公网ip
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.moqianfu.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-56.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/www.moqianfu.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
    
    # 接口代理配置!!!
    location /v1
    {
        proxy_pass http://47.**.***.**4:5657/v1;  # 公网ip
    }
    
    access_log  /www/wwwlogs/www.moqianfu.com.log;
    error_log  /www/wwwlogs/www.moqianfu.com.error.log;
}

如何用Nginx解决前端跨域问题?


链接远程mysql:

navicat连接mysql数据报错:10060unknown error,你可以这样做

相关文章

网友评论

      本文标题:Centos部署Flask

      本文链接:https://www.haomeiwen.com/subject/bjauzhtx.html