V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
bufu
V2EX  ›  Flask

项目部署之后访问弹出 Internal Server Error

  •  
  •   bufu · 2018-06-14 14:27:11 +08:00 · 8929 次点击
    这是一个创建于 2137 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Internal Server Error 各位哥哥姐姐帮帮看下

    运行环境 服务器操作系统:Ubuntu Server 16.04.1 LTS 64 位 项目开发部署方案:Falsk + nginx + uwsgi 在 python3.6 虚拟环境下运行的

    本地测试可以访问,部署上云服务器之后出现了这种问题。 然后查看了 logs 错误输出日志,发现报错如下: --- no python application found, check your startup logs for errors --- [pid: 4757|app: -1|req: -1/1] 139.214.254.164 () {40 vars in 841 bytes} [Wed Jun 13 22:42:12 2018] GET / => generated 0 bytes in 3 msecs (HTTP/1.1 500) 2 headers in 0 bytes (0 switches on core 0) Wed Jun 13 22:42:12 2018 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 306] during GET / (139.214.254.164) --- no python application found, check your startup logs for errors --- [pid: 4756|app: -1|req: -1/2] 139.214.254.164 () {40 vars in 841 bytes} [Wed Jun 13 22:42:12 2018] GET / => generated 0 bytes in 32 msecs (HTTP/1.1 500) 2 headers in 0 bytes (0 switches on core 0) --- no python application found, check your startup logs for errors --- [pid: 4757|app: -1|req: -1/3] 139.214.254.164 () {38 vars in 845 bytes} [Wed Jun 13 22:42:12 2018] GET /favicon.ico => generated 21 bytes in 27 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0) spawned uWSGI worker 4 (pid: 4759, cores: 1) spawned WSGI worker 5 (pid: 4760, cores: 1

    然后我多次在网上查询,大多说是 uwsgi 配置问题,我没有检查出来,所以这里也把配置贴出来罢

    [uwsgi]

    项目的路径

    chdir = /srv/webtest

    模块

    module = demo

    Python 虚拟环境的路径

    home = /root/.virtualenvs/benmoom-env-py3

    主进程

    master = true

    最大数量的工作进程

    processes = 10

    socket 文件路径,绝对路径

    socket = /srv/webtest/benmoom.sock

    wsgi 文件

    wsgi-file = /srv/webtest/demo.py

    wsgi 文件的 app 变量

    callable = app

    设置 socket 的权限

    chmod-socket = 666

    退出的时候是否清理环境

    vacuum = true

    3 条回复    2018-08-15 20:27:23 +08:00
    bufu
        1
    bufu  
    OP
       2018-06-16 11:42:11 +08:00
    没人?自己顶一下。
    bufu
        2
    bufu  
    OP
       2018-06-18 08:18:56 +08:00   ❤️ 1
    找到错误原因,在我的主 app 文件 demo.py 中这样写的:


    if __name__ == '__main__':
    app = create_app()
    app.run()


    乍一看没什么问题,这样写当然在本地运行也没啥问题。但是在服务上就会报错 python application found, check your startup logs for errors。这是因为在项目上线后,通过 uwsgi 服务器,给项目做一些非静态的处理,部分配置
    wsgi-file = /srv/webtest/demo.py
    callable = app

    如果,uwsgi 没有找到 demo.py 中的 app,项目就无法得到代理。项目无法正常访问,在浏览器上提示内部服务器错误就很正常了。uwsgi 启动没有报错,是因为这并不是 uwsgi 配置的错。

    修改如下:
    app = create_app()
    if __name__ == '__main__':
    app.run()
    h19981126g
        3
    h19981126g  
       2018-08-15 20:27:23 +08:00
    @bufu 我想问下我是 webpy 也是 nginx+uwsgi 出现了 ” Internal Server Error “要怎么改?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2872 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:07 · PVG 15:07 · LAX 00:07 · JFK 03:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.