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

2018-06-14 14:27:11 +08:00
 bufu

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

8946 次点击
所在节点    Flask
3 条回复
bufu
2018-06-16 11:42:11 +08:00
没人?自己顶一下。
bufu
2018-06-18 08:18:56 +08:00
找到错误原因,在我的主 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
2018-08-15 20:27:23 +08:00
@bufu 我想问下我是 webpy 也是 nginx+uwsgi 出现了 ” Internal Server Error “要怎么改?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/463088

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX