我正在尝试通过 CloudPanel 通过 uwsgi 在 Azure 上部署我的烧瓶应用

问题描述 投票:0回答:1

结果:内部服务器错误

注意:

  1. 我在这个特定的应用程序上使用 python 版本 3.8.16
  2. 我已经在下面提供的详细信息中删除了我的实际用户名和域
  3. 遵循以下确切步骤:https://www.cloudpanel.io/docs/v2/python/deployment/uwsgi/
  4. 我正在使用子域
  5. 我的应用程序在虚拟环境和我的本地机器上以开发模式正确运行
  6. uWSGI 也在监听 8090 端口。

这是我的应用程序主模块:

名称:api.py

from flask import Flask, request, jsonify, render_template
import joblib

app = Flask(__name__)
classifier = joblib.load('./model/pipeline.pkl')

@app.route('/')
def home():
    message = "API has been deployed correctly!"
    return render_template('index.html', message=message)

@app.route('/predict', methods=['POST'])
def predict():
    json_ = request.json

    prediction = classifier.predict(json_['text']).tolist()
    return jsonify({'prediction': prediction[0] })

if __name__ == '__main__':
    classifier = joblib.load('./model/pipeline.pkl')
    app.run(host='0.0.0.0')

这是我的 wsgi 文件:

from api import app

if __name__ == "__main__":
    app.run()

这是我的ini文件:

[uwsgi]
plugins       = python3
master        = true
protocol      = uwsgi
socket        = 127.0.0.1:8090
chdir         = /home/username/htdocs/api.domain.com
wsgi-file     = /home/username/htdocs/api.domain.com/api/wsgi.py
callable      = app

# In case you're using virtualenv uncomment this:
virtualenv = /home/username/htdocs/api.domain.com/env

# Needed for OAuth/OpenID
buffer-size   = 8192

# Reload when consuming too much of memory
reload-on-rss = 250

# Increase number of workers for heavily loaded sites
workers       = 4

# Enable threads for Sentry error submission
enable-threads = true

# Child processes do not need file descriptors
close-on-exec = true

# Avoid default 0000 umask
umask = 0022

#Run as weblate user
uid = username
gid = username

# Enable harakiri mode (kill requests after some time)
# harakiri = 3600
# harakiri-verbose = true

# Enable uWSGI stats server
# stats = :1717
# stats-http = true

# Do not log some errors caused by client disconnects
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true

这是我的虚拟主机文件:

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name api.domain.com;
  {{root}}

  {{nginx_access_log}}
  {{nginx_error_log}}

  if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
  }

  location ~ /.well-known {
    auth_basic off;
    allow all;
  }

  {{settings}}

  index index.html;

  location / {
    include uwsgi_params;
    uwsgi_read_timeout 3600;
    #uwsgi_pass unix:///run/uwsgi/app/weblate/socket;
    uwsgi_pass 127.0.0.1:8090;
  }

  #location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf)$ {
  #  add_header Access-Control-Allow-Origin "*";
  #  expires max;
  #  access_log on;
  #}

  if (-f $request_filename) {
    break;
  }
}

在重新启动 nginx 和 uwsgi 以及重新启动我的实例后,当我打开网站时它应该显示: enter image description here

nginx flask uwsgi
1个回答
0
投票

我正在使用 oracle 云,在部署 flask 应用程序时遇到同样的问题,它总是给我 500 或 502 错误,我发现许多其他问题,例如使用 ftp 与 couldpanel.io 连接,可能存在一些错误:/

© www.soinside.com 2019 - 2024. All rights reserved.