uWSGI/Flask:“未找到 python 应用程序,请检查您的启动日志是否有错误"; [英] uWSGI / Flask: "no python application found, check your startup logs for errors"

查看:48
本文介绍了uWSGI/Flask:“未找到 python 应用程序,请检查您的启动日志是否有错误";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 NGINX + uWSGI + Flask 运行的网站.

I have a website running with NGINX + uWSGI + Flask.

该网站大部分时间都运行良好,但有时它会进入一种状态,即 nginx 返回的页面仅显示内部服务器错误".如果我在执行此操作时查看 uWSGI 日志,则会看到以下内容:

The website runs fine most of the time, however every now and then it gets into a state where the pages returned by nginx just show "Internal Server Error". If I look at the uWSGI log when it's doing this, I see the following:

[pid: 1580|app: -1|req: -1/37] 69.162.124.228 () {46 vars in 716 bytes} [Sat May 12 10:25:13 2018] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---

它可以长时间处于这种状态,但如果我做了一些看似无关的事情,比如对烧瓶应用程序进行任意更改,那么一切都会重新开始工作.然后它将继续工作,直到一段时间后它再次开始给出内部服务器错误",而不会进行任何代码更改.

It can be in this state for ages, but if I do something seemingly unrelated, like make an arbitrary change to the flask app, then everything will start working again. It will then keep working until some random amount of time later when it starts giving "Internal Server Error" again, without any code changes being made.

我试过直接运行 uWSGI 应用程序,它运行没有任何错误.

I've tried running the uWSGI application directly, and it runs without any error.

我尝试在我的 Flask 应用程序上安装 Sentry 以捕获任何错误,但发生这种情况时没有任何显示.

I've tried installing Sentry on my flask app to capture any errors, but nothing shows up when this happens.

  • 我该如何诊断?

  • How do I diagnose this?

我还可以查看哪些其他日志文件?

What other log files can I look at?

可能导致这种情况的原因是什么?

What is likely to be causing this?

我已经在这工作了一个多星期,并且通读了几乎所有与 SO 相关的问题.我已经没有想法了,如果我不知道发生了什么,我几乎要放弃这个项目.任何帮助将不胜感激.

I've been at this for over a week now, and read through almost every related question of SO. I've run out of ideas, and near abandoning this project if I can't figure out what's going on. Any help would be greatly appreciated.

这是我的文件:

uWSGI 配置 (mysite.ini)

uWSGI config (mysite.ini)

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = mysite.sock
chmod-socket = 660
vacuum = true

die-on-term = true

logto = /var/log/uwsgi/%n.log

wsgi.py

from tunnelling.python.flask_app import app as application

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

nginx:

server {
    listen 80;
    server_name www.mysite.com;
    server_name mysite.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/dimraft/mysite/mysite.sock;
    }

   listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

系统文件:

[Unit]
Description=uWSGI instance to serve mysite
After=network.target

[Service]
User=dimraft
Group=www-data
WorkingDirectory=/home/dimraft/mysite
Environment="PATH=/home/dimraft/mysite/mysiteenv/bin"
ExecStart=/home/dimraft/mysite/mysiteenv/bin/uwsgi --ini mysite.ini

[Install]
WantedBy=multi-user.target

推荐答案

可能是你的 uWSGI 配置 (mysite.ini) 错误:

maybe your uWSGI config (mysite.ini) error:

改变:

module = wsgi:app

到:

module = projectName.wsgi:application

这篇关于uWSGI/Flask:“未找到 python 应用程序,请检查您的启动日志是否有错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆