Nginx django 502 bad gateway

I use uWSGI and Nginx to work on my Django site (version 1.4). My file structure is django_mysite / django_mysite /, which has a wsgi.py file in it.
I keep getting 502 Bad gateway errors. I have other servers working with 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() 

Error in the log:

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

thanks

+6
source share
3 answers

I found the following solution: the uwsgi.ini file that I created to create working Uwsgi did not specify a socket. So I made another .ini file and made a socket for it. The same socket that I placed in the nginx config file under uwsgi_pass. Here is a link to django web pages for configuring uwsgi.

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

+1
source

I ran into the same problem, but I understood it as follows.

If a third-party application is included in your project, it should be installed on your server in the same way as a south-side application. Consider the south included in your settings.py file, and then the south should also be installed on your server. If this module considers the south here, it is already installed on the server, and then try updating it. Since it is possible that you are using an updated version of the module on the local computer, and an older version is installed on the server.

+1
source

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

0
source

Source: https://habr.com/ru/post/920730/


All Articles