502 Bad Gateway在部署Flask应用程序时出错Nginx和uWSGI

时间:2013-07-17 19:34:10

标签: nginx uwsgi

我正在尝试在运行Ubuntu 10.10的Linode VPS上部署Flask应用程序。我一直在关注本教程(https://library.linode.com/web-servers/nginx/python-uwsgi/ubuntu-10.10-maverick#sph_configure-nginx),但我一直收到502 Bad Gateway错误。

这是/ etc / default / uwsgi:

PYTHONPATH=/var/www/reframeit-im
MODULE=wsgi

这是/var/www/reframeit-im/wsgi.py:

# add the application directory to the python path
import sys
sys.path.append("/var/www/reframeit-im")

# run flask app
from reframeit import app as application

这是应用程序的nginx配置文件,它与符号链接到/ sites-enabled目录(/ opt / nginx / conf / sites-enabled / reframeit-im):

server {
    listen 80;
    server_name www.reframeit-im.coshx.com reframeit-im.coshx.com;
    access_log /var/www/reframeit-im/logs/access.log;
    error_log /var/www/reframeit-im/logs/error.log;

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9001;
    }
}

我检查了应用程序的nginx错误日志,我发现了这个:

2013/07/17 19:30:19 [error] 20037#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 70.88.168.82, server: www.reframeit-im.coshx.com, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:9001", host: "reframeit-im.coshx.com"

我的配置有问题吗?

2 个答案:

答案 0 :(得分:1)

使用uwsgi_pass 127.0.0.1:9001;你向Nginx声明了你想通过TCP套接字与uWSGI通信的意图,但是没有向uWSGI发出警告。

尝试在/etc/default/uwsgi文件中添加相应的套接字行:

PYTHONPATH=/var/www/reframeit-im
MODULE=wsgi
socket=127.0.0.1:9001

答案 1 :(得分:0)

除了Flavio的建议外,请添加“protocol = uwsgi”。如下

PYTHONPATH=/var/www/reframeit-im
MODULE=wsgi
socket=127.0.0.1:9001
protocol = uwsgi