nginx django 502坏网关 [英] nginx django 502 bad gateway

查看:391
本文介绍了nginx django 502坏网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用uWSGI和Nginx来服务我的Django网站(1.4版本)。我的文件结构是django_mysite / django_mysite /,其中有一个wsgi.py文件。

我不断得到502错误的网关错误。我有其他运行nginx的服务器,并且工作正常。



我的nginx配置:

  server {
listen 80;
server_name beta.example.com;

keepalive_timeout 70;

root / path / to / django_mysite / django_mysite;


位置根{
root html;
uwsgi_pass localhost:9000;
uwsgi_param UWSGI_SCRIPT django_wsgi;
包括uwsgi_params;
}

位置/ {
uwsgi_pass localhost:9000;
包括uwsgi_params;
uwsgi_param SCRIPT_NAME / django;
uwsgi_param UWSGI_SCRIPT django_wsgi;
uwsgi_modifier1 30;
}
}

我的wsgi.py文件:
导入sys
import os

  sys.path.append('/ path / to / django_mysite /')
os.environ.setdefault(DJANGO_SETTINGS_MODULE,django_mysite.settings)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

日志中的错误是:

  * 3 recv()失败(104:连接由对等体重置)从上游读取响应头

谢谢

解决方案

我发现的解决方案是:
the uwsgi.ini我创建uwsgi工作的文件没有指定套接字。所以我制作了另一个.ini文件,并为它制作了一个套接字。同样的插槽,我放在uwsgi_pass下的nginx conf文件中。这是一个链接到django的网页来配置uwsgi。



I am using uWSGI and Nginx to server up my Django website (1.4 version). My file structure is django_mysite/django_mysite/ in which there is a wsgi.py file.
I keep getting 502 Bad gateway errors. I have other servers running of nginx and they are working fine.

My nginx config:

server {
  listen      80;
  server_name beta.example.com;

  keepalive_timeout 70;

  root /path/to/django_mysite/django_mysite;


  location root {
        root   html;
        uwsgi_pass   localhost:9000;
        uwsgi_param UWSGI_SCRIPT django_wsgi;
        include        uwsgi_params;
    }

  location / {
        uwsgi_pass   localhost:9000;
        include        uwsgi_params;
        uwsgi_param SCRIPT_NAME /django;
        uwsgi_param UWSGI_SCRIPT django_wsgi;
        uwsgi_modifier1 30;
    }
}

My wsgi.py file: import sys import os

sys.path.append('/path/to/django_mysite/')
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_mysite.settings")

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

The error in the log is:

*3 recv() failed (104: Connection reset by peer) while reading response header from upstream

Thanks

解决方案

The solution I found was this: the uwsgi.ini file that I made to create the uwsgi workers didn't specify a socket. So I made another .ini file and made a socket for it. That same socket I placed into the nginx conf file under uwsgi_pass. Here is a link to django's webpages for configuring uwsgi.

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/uwsgi/

这篇关于nginx django 502坏网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆