Getting 502 Bad Gateway after restarting gunicorn

July 31, 2018 650 views
Django Ubuntu 16.04

I'm using a one-click app to deploy a Django site using Putty and WinSCP. I was fixing syntax errors in translating my code from Python 3 / Django 2.0 to Python 2 / Django 1.8 (mostly in my urls.py files and my settings), as the virtual machine runs only up to Python 2 / Django 1.8. When I did the command systemctl restart gunicorn.service (usually was using service restart gunicorn) the page no longer gave me the syntax error with all of the exception details, it just gave me a 502 Bad Gateway nginx/1.10.3 (Ubuntu) page. Could this be a sign that my urls.py files and everything has worked and that there is another bug to be fixed now? Or have I dug myself a deeper hole somehow.. I think it's the latter Either way, advice on how to fix it would be super appreciated. I came across some pages on Digital Ocean Community that advised to change the 2 ALLOWED_HOSTS variables in my settings.py but that didn't work. If you have a specific piece of advice that includes that, though, please share it because I may not have tried it.

Here are some of my latest error logs:

2018/07/31 05:47:10 [error] 2216#2216: *402 upstream prematurely closed connection while reading response header from upstream, client: xxxxxx, server: _, request: "GET / HTTP/1.0", upstream: "http://unix:/home/django/gunicorn.socket:/"
2018/07/31 06:12:27 [error] 2216#2216: *404 upstream prematurely closed connection while reading response header from upstream, client: xxxxxx, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxxxxx"
2018/07/31 06:17:06 [error] 2216#2216: *406 upstream prematurely closed connection while reading response header from upstream, client: xxxxxx, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxxxxx"
2018/07/31 06:17:07 [error] 2216#2216: *406 upstream prematurely closed connection while reading response header from upstream, client: xxxxxx, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "xxxxxx"
1 Answer

Hello friend!

It is difficult to say with any certainty as the error in question can mask many issues. It basically means that the web server couldn't get what it needed from the backend, and that you need to troubleshoot the backend to find out why. Do the gunicorn logs have anything different in them? Often they will have more detail.

Kind Regards,
Jarland

  • I figured it out.. sort of. Basically my I turned my Debug to False while I still have other errors to fix. Thank you for explaining, though

Have another answer? Share your knowledge.