nginx django 502 bad gateway

2019-06-18 17:29发布

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

3条回答
来,给爷笑一个
2楼-- · 2019-06-18 18:09

I was facing the same issue, but i figered it out in following way.

If third party app included in your project then it should be installed on your server also like south is third party app. Consider south is included in your settings.py file then south should be installed on your server also. If that module consider south here, is already installed on server then try to upgrade it. Because it is possible that you are using upgraded version of module on local machine and older version is installed in the server.

查看更多
够拽才男人
3楼-- · 2019-06-18 18:20

In my case the problem was with the uwsgi configuration. I added buffer-size = 65535 in the uwsgi conf of my application and the problem with error 502 was resolved on the server

查看更多
霸刀☆藐视天下
4楼-- · 2019-06-18 18:27

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/

查看更多
登录 后发表回答