首页 > flask应用使用uWSGI和Nginx 部署出现的奇怪问题

flask应用使用uWSGI和Nginx 部署出现的奇怪问题

学习flask做了一个小博客,大体功能做完了想学习一下部署过程,正好有一台搬运工VPS,就在上面尝试部署,使用的是uWSGI和Nginx ,
项目构成如下:

使用了Blueprint,auth文件夹下是关于处理登陆操作修改密码邮箱等验证操作的,main是博客相关程序。
现在使用命令:
python mananage.py runserver --host 0.0.0.0

一切正常,但是在uWSGI和Nginx 环境下,有些功能正常,有些功能报错:
502 Bad Gateway。

ngnix配置如下:

uwsgi配置:

[uwsgi]
plugins=python
vhost=true
socket=127.0.0.1:9001

查看Nginx 错误也没有发现什么问题

通过查看myuwsgi日志文件发现报如下错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)

但是我在启动文件已经加入如下代码:

if __name__ == '__main__':
    import sys
    reload(sys)
    sys.setdefaultencoding("utf-8")
    manager.run()

另外其他有中文的py文件开头都已经加上#encoding: utf-8

ngnix日志的error.log文件内容如下:

2015/01/23 09:41:28 [error] 18361#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 122.96.137.42, server: , request: "GET /auth/login HTTP/1.1", upstream: "uwsgi://127.0.0.1:9001", host: "104.224.169.47", referrer: "http://104.224.169.47/"

access.log如下图所示:


以前遇到这个错误,多数是nginx无法连接到uwsgi,原因可能是uwsgi没有起,或者程序有问题等,其实这些错误都可以在nginx和uwsgi的日志中看到,查看一下日志,贴出来看看

【热门文章】
【热门文章】