宝塔部署flask项目

发布时间:2023年12月18日

宝塔(bt.cn)部署flask项目,发现问题还挺多。不过终于是搞定了。

先可以用pycharm建一个空的flask项目,这样好发现问题。

到网站栏目点击python项目,新建一个python项目。

要选择flask框架,uwsgi运行方式。

端口如果选择80端口,很可能会出现80端口已占用,那就需要修改php占用80端口的配置文件了。

一般就在0.default.conf 和 phpfpm_status.conf 两个文件里。

0.default.conf

server
{
    listen 81;
    server_name _;
    index index.html;
    root /www/server/nginx/html;
}

phpfpm_status.conf

server {
    listen 81;
    server_name 127.0.0.1;
    allow 127.0.0.1;
    location /nginx_status {
        stub_status on;
        access_log off;
    }
    location /phpfpm_52_status {
        fastcgi_pass unix:/tmp/php-cgi-52.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_53_status {
        fastcgi_pass unix:/tmp/php-cgi-53.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_54_status {
        fastcgi_pass unix:/tmp/php-cgi-54.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_55_status {
        fastcgi_pass unix:/tmp/php-cgi-55.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_56_status {
        fastcgi_pass unix:/tmp/php-cgi-56.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_70_status {
        fastcgi_pass unix:/tmp/php-cgi-70.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_71_status {
        fastcgi_pass unix:/tmp/php-cgi-71.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_72_status {
        fastcgi_pass unix:/tmp/php-cgi-72.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_73_status {
        fastcgi_pass unix:/tmp/php-cgi-73.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_74_status {
        fastcgi_pass unix:/tmp/php-cgi-74.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_75_status {
        fastcgi_pass unix:/tmp/php-cgi-75.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_80_status {
        fastcgi_pass unix:/tmp/php-cgi-80.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_81_status {
        fastcgi_pass unix:/tmp/php-cgi-81.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
    location /phpfpm_82_status {
        fastcgi_pass unix:/tmp/php-cgi-82.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }
}

可以把端口修改成81等。?

?把它们80端口都修改一下。80端口就可以填进去了。

到这个界面就部署完了,这个界面宝塔不能退出,需要手动刷新一下。

?这个时候配置没有完成,需要到设置里,将用户权限切换到root。

这个时候应该就可以使用ip地址打开flask网站,如果在项目日志里说uwsgi找不到application,那就是flask主函数没有修改,应该是这样:

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def gen():
    return render_template('index.html')


if __name__ == '__main__':
    app.run()
else:
    application = app

要加上? application = app 这样的代码,uwsgi才能找到application。

文章来源:https://blog.csdn.net/andux/article/details/135057462
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。