【问题标题】:502 Bad Gateway Django502 错误网关 Django
【发布时间】:2013-06-23 13:57:57
【问题描述】:

我有一个简单的应用程序,允许您将图像上传到服务器,它设置在我的生产服务器上,由 django + uwsgi + ngnix 组成。

我在尝试上传图片时遇到问题。我收到以下错误:

错误

502 Bad Gateway
nginx/1.2.1

功能:

def upload(request):
    form = ImageForm()
    context = {'form':form,}
    context.update(csrf(request))


    if request.POST:
        form = ImageForm(request.POST, request.FILES)
        if form_is.valid():

            image = request.FILES.get('image')
            CarPhoto.objects.create(user=request.user,cars=1,description='dwq',image=image)
            return HttpResponseRedirect(reverse('transformer:kevin'))
    return     render_to_response('image.html',context,context_instance=RequestContext(request))

模板

 <form method="POST" enctype="multipart/form-data" action=".">

 {% csrf_token %}
 <div id="c">image</div> {{form.image}}
    <input type = "submit" value= "add" id="box2"/>
 </form>

mysite.com_error.log

 "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:07:39 [error] 28870#0: *5 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:08:12 [error] 29065#0: *5 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:08:18 [error] 29065#0: *7 readv() failed (104: Connection reset by peer) while reading upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:09:11 [error] 29065#0: *9 readv() failed (104: Connection reset by peer) while reading upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:09:52 [error] 29065#0: *14 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
 2013/06/26 12:10:51 [error] 29065#0: *19 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 313.19.220.424, server: mysite.com, request: "POST /car/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"

【问题讨论】:

标签: django


【解决方案1】:

听起来您的 uWSGI 实例已经死亡或以不知道如何回答的方式失败。

除了 uWSGI 日志之外,还可以查看 nginx 日志,看看它会走多远。

也许您上传的文件太大,以至于阻塞了一些前端流传输部分。

编辑您的帖子以指示两个日志文件的输出,我们将看到。

【讨论】:

    【解决方案2】:

    如果您的项目中包含第三方应用程序,那么它应该安装在您的服务器上,就像南方是第三方应用程序一样。 考虑 south 包含在您的 settings.py 文件中,那么 south 也应该安装在您的服务器上。 如果该模块在这里考虑南方,已经安装在服务器上,然后尝试升级它。因为您可能在本地机器上使用升级版模块,而服务器中安装了旧版本。

    【讨论】:

      猜你喜欢
      • 2020-09-29
      • 2012-07-16
      • 2021-06-30
      • 2022-07-01
      • 2012-05-28
      • 2018-12-05
      • 2012-05-30
      • 1970-01-01
      • 2017-07-07
      相关资源
      最近更新 更多